设该文件名为1234.txt且在当前目录下。
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
#include "stdlib.h"
int main(void){
FILE *fp;
char tmp[21];
int sum=0;
if((fp=fopen("1234.txt","r"))==NULL){
printf("Open the file failure...\n");
exit(0);
}
while(fscanf(fp,"%c",tmp),!(*tmp>='a' && *tmp<='z' || *tmp>='A' && *tmp<='Z'));
ungetc(*tmp,fp);
while(fscanf(fp,"%[a-zA-Z]%*[^a-z^A-Z]",tmp)>0)
sum++;
fclose(fp);
printf("There is(are) %d words in the article.\n",sum);
return 0;
}