1、
#include <stdio.h> int main(void) { FILE *fp; int ch; char filename[FILENAME_MAX]; printf("Please input the filename: "); scanf("%s", filename); if((fp = fopen(filename, "r")) == NULL) printf("\aFile open failed.\n"); else { int i = 0; while((ch = fgetc(fp)) != EOF) { if(ch == '\n') i++; } fclose(fp); printf("This file has %d line(s).\n", i); } return 0; }

















