Count number of line using C

后端 未结 5 1385
无人共我
无人共我 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:09

    Please think for a moment about what you have to do to count lines in a file:

    1. Open the file for reading, maybe with fopen( );

    2. Read each line, one line at a time, maybe with fread( );

    3. Increment a line counter that you've initialized to zero earlier;

    4. Whwn end-of-file is returned from the next read of the file, you are done. printf( ) the line counter.

提交回复
热议问题