Reading a C file, read an extra line, why?

前端 未结 6 1881
余生分开走
余生分开走 2020-12-21 05:12

I don\'t know exactly why a file pointer reads an extra line from a file, specifically the last line, here is the code:

FILE *fp ;
fp = fopen (\"mac_ip.txt\"         


        
6条回答
  •  天涯浪人
    2020-12-21 05:53

    You better test for fscanf return value before printing result. I bet that in the last iteration of your loop, fscanf calls fail and you print the last returned results.

提交回复
热议问题