I read two binary numbers which are separeted by a coma(1010,1000111) from a texfile into two differen linkedlist as below:
while (!feof(fout))
{
ch=fgetc(fout);
if(ch==','){
printf("\n");
control=1;
}else{
if(control==0){
if(ch=='1' || ch=='0'){
curr = (item *)malloc(sizeof(item));
curr->val = ch;
curr->next = head;
head = curr;
length1++;
}
}else{
if(!feof(fout)){
if(ch=='1' || ch=='0'){
curr2 = (item *)malloc(sizeof(item));
curr2->val = ch;
curr2->next = head2;
head2 = curr2;
length2=(length2+1);
}
}
}
}
}
Then I put them into array (I will show just for one number)
curr = head;
while(curr){
binary1[x]=curr->val;
curr = curr->next ;
x++;
}
Then I will convert these binary numbers to decimal:
char number1[x];
printf("\n\nBinary1:\t ");
for(i = 0; i < x; i++)
number1[i]= (binary1[x-1-i]);
for(i = 0; i < x; i++)
printf("%c", number1[i]);
printf("\nconversion is : %d\n", convert_bin2dec(number1));
But in my binary and number1 array that are some other special character that I could not recognize, and as a result of that convert_bin2dec function does not work
conver_bin2dec(char * str) accepts this:
char str[20]="1110";
as a paramater.
Why binary1 and number1 includes characters other than 1,0?
Please help..