keyser_soze 15 Newbie Poster
float x;
scanf("%d",&x);

x is a float value so in the scanf statement u should use %f instead of %d.

.....cheers

keyser_soze 15 Newbie Poster
#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 :)

i think when u write this

for(i=0;i<8;i++)

the code will only work if you enter exactly 8 digits...otherwise it will cause an error..so try writing it like this

for(i=0;i<strlen(input);i++)

hope this helps...cheers

keyser_soze 15 Newbie Poster

Wash your mouth out with soap. main() returns int.

Ok i made a mistake like all other newbies [should have been int main(void)]...
but grumpier take an advice stop being grumpy
and btw wash your tongue with soap and rinse it properly with
shampoo and maybe just maybe it could wash off that
sour spot off your tongue...cheers

devnar commented: Just take the damn advice and let it go at that. Don't pollute the thread. +0
WaltP commented: Some people can't handle what they dish out, can they? :-) +15
keyser_soze 15 Newbie Poster
void main()
{
	int sec_code=0;
	do
	{
		scanf("%d",&sec_code);
	}while((sec_code<1||sec_code>4)&&printf("invalid section code"));
}

Try this code works perfectly for me....