decoder.c
721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <string.h>
#include "auxiliar.h"
#include <math.h>
int main(int argc, char **argv)
{
int i;
if(argc != 2)
{
error();
}
char *input = argv[1];
if(!strcmp(input,"error"))
{
error();
}
char **inputs = comma_separate(input);
if(inputs == NULL)
{
error();
}
int num_inputs = num_occurrences(input,',');
if(num_inputs != 1)
{
error();
}
int selected = bin2dec(inputs[0]);
int num_outputs = pow(2,strlen(inputs[0]));
for(i = 0; i < num_outputs; i++)
{
if(i == selected)
{
printf("1");
}
else
{
printf("0");
}
if(i != (num_outputs-1))
{
printf(",");
}
}
free_mem(inputs,num_inputs);
return 0;
}