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. "); else { int i = 0; while((ch = fgetc(fp)) != EOF) { if(ch == ' ') i++; } fclose(fp); printf("This file has %d line(s). ", i); } return 0; }