问题:一个文件中有一段英文,统计其中英文的个数
代码:
main(){
int count=0,i=0,lean=0;
FILE *fp;
if((fp=fopen("D:/1.txt","r"))==NULL){
printf("error!");
exit(0);
}
char ch;
while(1){
if((ch=fgetc(fp))==EOF){
break;
}
if(ch>='A'&&ch<='Z'||ch>='a'&&ch<='z'||ch=='%'){
if(lean==0){
count++;
}
lean=1;
}else{
lean=0;
}
}
printf("\n%d",count);
fclose(fp);
}