#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main(){
char input[10];
int i,j,digit,out[10],flag=0,sum;
while(flag==0){
sum=0;
flag=0;
strcpy(input," ");
scanf("%s",&input);
fflush(stdin);
digit=strlen(input);
printf("%d\n",flag);
if(strlen(input)>8){break;}
/*else {
for(i=0;i<8;i++){
if (input[i]!=48&&input[i]!=49){
flag++;
break;
}
}
}*/
printf("%d\n",digit);
printf("%d",flag);
if (flag==1){break;}
for(i=0;i<8;i++){
if(input[i]!='\0'){
if(input[i]=='1'){
out[i]=1;}
else if(input[i]=='0'){
out[i]=0;}
}
}
j=1;
for(i=0;i<digit;i++){
sum+=out[i]*pow(2,digit-j);
j++;
}
printf("Decimal = %d",sum);
}
}
Program closed right after I input any character, if I un-comment codes I commented up there. The code I commented supposed to be filter for non binary number so if non binary number is inputted, the the program terminates.
Anyway I got hint about adding code 'atoi' to ease it up. Still i got no idea how to separate each number afterward.
Please help :)