我有一个processs.txt文件,其中包含有关传入进程的详细信息,
0 4 96 30
3 2 32 40
5 1 100 20
20 3 4 30
我想找到此文件中的行数。该怎么办?
我尝试过此代码,但始终将行数返回为0
char c;
int count = 0;
// fp is the pile pointer
for (c = getc(fp); c != EOF; c = getc(fp))
if (c == '\n') // Increment count if this character is newline
count = count + 1;
也许您执行此操作时文件结尾??并且您需要从头开始
int c; // c must be int
int count = 0;
// fp is the pile pointer
rewind(fp); // back to beginning, clear error
for (c = getc(fp); c != EOF; c = getc(fp))
if (c == '\n') // Increment count if this character is newline
count = count + 1;