Here my question I need a decoder for binary codes from a text file but the problem is when I put a space in the text file tpos values crash I know what the problem is the while(fgets(buf, 8, fb) != NULL) because some binary codes are only 6 characters long like the space 100000 binary codes and the numbers unlike the letters which are 7 binary codes long can you guys help me come up with a expression or what should I do in these situation tnx in advance
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int decimalConverter(int num)
{
int bnum, dec = 0, base = 1, rem ;
bnum = num;
while( num > 0){
rem = num % 10;
dec = dec + rem * base;
num = num / 10 ;
base = base * 2;
}
return dec;
}
main()
{
char buf[50];
int a, ab;
char abc;
FILE *f;
FILE *fb;
f = fopen("test.txt","r");
fb = fopen("encoder.txt","r");
while(fgets(buf, 8, fb) != NULL){
a = atoi(buf);
ab = decimalConverter(a);
abc = (char)ab;
printf("%c", abc);
}
printf("\n");
}
the text file looks like this or somthing like this
Text File
100000101100011000001001010