#include
int main(int argc, char * argv[])
{
FILE * fp;
int c;
int nCount = 0;
fp = fopen(argv[1], "r");
while (1)
{
c = fgetc(fp);
if(c == EOF)
{
printf("英文字符数:%d", nCount);
break;
}
if (c<=126)
nCount ++;
}
fclose(fp);
getchar();
}
当然,程序还不完整,要加些异常处理之类的东西等,大体就是这样的,你自己去做吧,呵呵。
统计英文字母数。
#include
#include
FILE *fin;
void main(int argc, char *argv[]){
char namein[64];
int gb;
int NN=0;
if (argc < 2) {
printf("\007Usage: %s filename\n", argv[0]);exit(0);
};
strcpy(namein,argv[1]);
if ( ( fin = fopen(namein,"r")) == NULL){
printf("Can not open %s\n",namein); exit(0);
};
while(1){
gb=fgetc(fin);
if (gb==EOF) break;
if (gb >= 'a' && gb <= 'z' ) NN=NN+1;
if (gb >= 'A' && gb <= 'Z' ) NN=NN+1;
}
fclose(fin);
printf("%d letters\n",NN);
}