Why fscanf not working as expected for subsequent calls?
char s[20];
fscanf(stream, "%s", s);
I found that it can only work for the first time, subsequent calls will fail.
(gdb) p fscanf(stream, "%s", s)
$15 = 1
(gdb) p开发者_StackOverflow (char *)s
$17 = 0x7fffffffe770 ""
From the above can see that fscanf
matches 1
character, but not stored to s
?
UPDATE
Is there a way to get corresponding file name of FILE*
?
file content:
a
abc
b
c
e
f
h
hi
fscanf et al return the number of items converted, not the number of bytes or characters. So you are successfully converting one item, a string in this case, which happens to be empty (""
).
精彩评论