Hello again,
Yet another beginner question...
I'm sure you wouldn't ever use scanf like this in practive, but I stuck the "/" in just to see what would happen. When I ran the program, I entered "hello / world". I expected that:Code:#include <stdio.h> int main() { char i[20], j[20]; scanf("%s/%s", i, j); printf("%s %s", i, j); return 0; }
1. "hello" would be stored in i,
2. the "/" would be ignored, since it is identical to the "/" in the format string,
3. "world" would be stored in j,
so the output should be "hello world".
However this isn't the case. All that is output is "hello" followed by a white space and four unrecognisable characters.
If I type in "xyz" followed by enter, the program outputs "xyz" followed by the same unrecognisable characters. That I really don't understand, since scanf has surely only read in one string at this point and should be expecting more input - it beats me why the program should pass beyond scanf at all.
Any suggestions as to what I am overlooking would be most appreciated. Incidentally, I am using Code::Blocks.