#include <stdio.h>
int main() {
FILE *fp = fopen("example.c", "r");
if (fp == NULL) {
printf("Failed to open file\n");
return 1;
}
int line_count = 0;
int c;
while ((c = fgetc(fp)) != EOF) {
if (c == '\n') {
line_count++;
}
}
fclose(fp);
printf("The file has %d lines\n", line_count);
return 0;
}
01使用fopen,fgetc,fputc来统计一个.c文件的行数
于 2023-07-01 12:47:04 首次发布