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 == ' ') lines++; } printf("lines = %d ", lines); fclose(fp); } return 0; }