fgets from stdin problems [C]

后端 未结 3 505
清歌不尽
清歌不尽 2021-01-07 01:08

I\'m writing a program that works with files. I need to be able to input data as structures, and eventually read it out. The problem i have at the moment is with this code:<

3条回答
  •  Happy的楠姐
    2021-01-07 01:46

    The newline is still in stdin from a prior call to a function that didn't read a newline from input. Clear stdin by reading until you've read out the newline -- not by flushing stdin as others have suggested.

    EDIT: Thanks Alok, for the correction!

提交回复
热议问题