when i enterCode:char array1[50]; scanf("%s", array1); printf("\nYou entered: %s\n", array1);
"hello world"
it puts only the word "hello" in array1
when i enterCode:char array1[50]; scanf("%s", array1); printf("\nYou entered: %s\n", array1);
"hello world"
it puts only the word "hello" in array1
Last edited by transgalactic2; 10-24-2008 at 12:45 PM.
It's not a bug. scanf() by definition is only going to read up until the first space or new line.
Check this code snippet out to see.
Code:#include <stdlib.h> #include <stdio.h> int main(int argc, char * argv[]) { char string1[20], string2[20]; scanf("%s %s", string1, string2); printf("%s %s", string1, string2); return 0; }
Since that's what it's supposed to do, the word "bug" seems a bit over-the-top.
what happens to the next word "world"
is it eliminated or it added to the start of the next input string?
Something like that, yes.
You are wanting to do something like this:
Example:
Code:char line[256]; fgets(line, sizeof(line), stdin); strtok(line, "\n"); printf("You typed: \"%s\"", line);
puts reads all the inputted string
puts doesn't read anything. If you mean fgets, then yes.
i meant gets
sorry
gets reads every thing?
how its bad?
gets doesnt know the size of the inputed string so it ma cause bufferoverflow