Mail Archives: djgpp/2002/04/25/01:15:10
On Thu, 25 Apr 2002, Goh, Yong Kwang wrote:
> tMain
> tMain
>
> D:\TEMP>
> ---END---
>
> Notice the last token "tMain" got printed twice which infers that the loop
> was repeated another 1 last time after the last token.
That's expected behavior for the code you wrote.
> So is there any easy way to overcome this problem, or do I have to do the
> tokenizing and parsing character by character using fgetc instead for the
> program to work more reliably?
It's generally recommended to use fgets (followed by sscanf) in such
cases, not fscanf. If you must use fscanf, you will have to design your
format conversion string carefully (for example, include a \n in it),
and/or look at the value fscanf returns, instead of ignoring it.
- Raw text -