Monday, May 24, 2010

How to input a binary string bit by bit in C?

input a string array in the same way u do for integers.


char arr[20];


for(int a=0;a%26lt;=20;a++)


{


scanf("%c",%26amp;arr[a]);


}

How to input a binary string bit by bit in C?
Strait C? Not C++... boy it's been a long time!





I would recommend storing the values in a char array and then converting the result after it was all input.





#include %26lt;stdio.h%26gt;


char line[100];


printf("Enter Binay String");


fgets(line, sizeof(line), stdin);
Reply:Use cin in a for loop?
Reply:/* this code will promt u to enter d string until u press ENTER key.....





char ch;


char string[100];


int i=0;





while( ch != 13) // 13 is ascii value for "enter" or carriage return..


{


ch = getchar();


string[i]=ch;


i++;


}


No comments:

Post a Comment