c语言 13 - 6
1、
#include <stdio.h> int main(void) { FILE *fp; int ch; char filename[FILENAME_MAX]; printf("please input filename: "); scanf("%s", filename); if((fp = fopen(filename, "r")) == NULL) printf("\afile open fialed."); else { int lines = 0; while((ch = fgetc(fp)) != EOF) { if(ch == '\n') lines++; } printf("lines = %d\n", lines); fclose(fp); } return 0; }