#include <stdio.h> int main() { FILE *fp = fopen("1.txt", "r+");//打开文件 if(NULL == fp) { perror("open 1.txt"); return -1; } int count = 0; char ch; while((ch = fgetc(fp)) != -1) { count++; } printf("count = %d\n", count); return 0; }