negator.c
597 Bytes
#include <stdio.h>
#include <string.h>
#include "auxiliar.h"
int main(int argc, char **argv)
{
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 input_length = strlen(inputs[0]);
int num = bin2dec(inputs[0]);
num *= -1;
char *result = dec2bin(num,input_length);
printf("%s",result);
free(result);
free_mem(inputs,num_inputs);
return 0;
}