How to use feof(FILE *f)?

后端 未结 3 1839
野的像风
野的像风 2020-12-06 22:55

I\'m having a hard time with a do-while loop, that is supposed to stop when we reach the end of the file. Here\'s the loop code:

do  {
    if (pcompanyRow[0]         


        
3条回答
  •  无人及你
    2020-12-06 23:44

    I would change your loop and logic to use this:

    while (fgets(pcompanyRow, 1024, f) != NULL) {
    
        /* do things */
    
    }
    

    when fgets() attempts to read past the end of the file, it will return NULL and you'll break out of the loop. You can still continue to use pass and your other flags/logic, but the conditions you check for will be slightly different.

提交回复
热议问题