fgets() not working after fscanf()

前端 未结 3 1680
误落风尘
误落风尘 2020-12-21 15:49

I am using fscanf to read in the date and then fgets to read the note. However after the first iteration, fscanf returns a value of -1.

I used GDB to debug the progr

3条回答
  •  一整个雨季
    2020-12-21 16:20

    Don't mix fscanf() and fgets(), since the former might leave stuff in the stream's buffer.

    For a line-oriented format, read only full lines using fgets(), then use e.g. sscanf() to parse what you've read.

提交回复
热议问题