If a user enters
0 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0
how do I read it in as
00000000111010000000011111100000
Read it one character at a time, then if it's not a space add it to a character array.
it's integers not characters
I have this code snippet, but it only works if each value is separated by one whitespace character
fgets(z, sizeof(z),stdin);
tk = strtok(z," ");
while( tk != NULL){
c[index] = atoi(tk);
index++;
tk = strtok (NULL, " ");
}
Read it as characters and convert the character '0' to the number 0.
fgets(z, sizeof(z),stdin);
tk = strtok(z," ");
while( tk != NULL){
c[index] = atoi(tk);
index++;
tk = strtok (NULL, " ");
}
Keep the fgets()
statement. Throw out the rest.
Loop through the buffer read and follow what I said above.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.