Reading one line at a time in C

后端 未结 10 868
萌比男神i
萌比男神i 2020-12-01 13:01

Which method can be used to read one line at a time from a file in C?

I am using the fgets function, but it\'s not working. It\'s reading the space

10条回答
  •  时光取名叫无心
    2020-12-01 14:00

    The fgets function will read a single line from a file or num characters where num is the second parameter passed to fgets. Are you passing a big enough number to read the line?

    For Example

    // Reads 500 characters or 1 line, whichever is shorter
    char c[500];
    fgets(c, 500, pFile);
    

    Vs.

    // Reads at most 1 character
    char c;
    fgets(&c,1,pFile);
    

提交回复
热议问题