Count number of line using C

后端 未结 5 1387
无人共我
无人共我 2020-12-16 07:58

Is there a way to count the number of lines in my file using C?

5条回答
  •  眼角桃花
    2020-12-16 08:07

    If you are referring to the line number within your c source, most compilers support the __LINE__ macro. If you want to count line numbers of arbitrary text files in c, the following functions should be starting points:

    • fopen() to open a file for reading
    • fgets() to read lines
    • eof() to check for end of file
    • fclose() to close the file

    Combining these into a line counter is left as an exercise to the reader :)

提交回复
热议问题