#include <stdio.h>
#include <string.h>
int main(void){
FILE *file;
int count_char = 0;
int count_line = 0;
char c;
file = fopen("admin.c","r");
if(!file){
printf("文件打开失败!");
return 1;
}
while((c = fgetc(file)) != EOF){
count_char++;
if(c == '\n'){
count_line++;
}
count_line++; //最后一行没有'\n' 所以最后还要 +1
}
printf("字符数:%d\t行数:%d",count_char,count_line);
return 0;
}
while((c = fgetc(file)) != EOF) 里面, c = fgetc(file) 记得 再加个括号,文本的结束符是 EOF