70,037
社区成员
发帖
与我相关
我的任务
分享#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int c,i,letter[26];
FILE *ifp,*ofp;
if(argc!=3){
printf("\n%s%s%s\n\n%s\n\n",
"usage: ",argv[0],"infile outfile",
"The uppercase letters in infile will be counted.",
"The result will be written in outfile.");
exit(1);
}
ifp=fopen(argv[1],"r");
ofp=fopen(argv[2],"w");
for(i=0;i <26;++i)
letter[i]=0;
while((c=getc(ifp))!=EOF)
if(c>='A'&&c <='Z')
++letter[c-'A'];
for(i=0;i <26;++i){
if(i%6==0)
putc('\n',ofp);
fprintf(ofp,"%c:%5d ",'A'+i,letter[i]);
}
putc('\n',ofp);
fclose(ifp);
fclose(ofp);
return 0;
}
======================================
A: 3 B: 0 C: 0 D: 1 E: 0 F: 2
G: 0 H: 0 I: 0 J: 0 K: 0 L: 0
M: 0 N: 0 O: 0 P: 0 Q: 0 R: 0
S: 2 T: 0 U: 0 V: 0 W: 0 X: 0
Y: 0 Z: 0
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int c,i,letter[26];
FILE *ifp,*ofp;
if(argc!=3){
printf("\n%s%s%s\n\n%s\n\n",
"usage: ",argv[0],"infile outfile",
"The uppercase letters in infile will be counted.",
"The result will be written in outfile.");
exit(1);
}
ifp=fopen(argv[1],"r");
ofp=fopen(argv[2],"w");
for(i=0;i <26;++i)
letter[i]=0;
while((c=getc(ifp))!=EOF)
if(c>='A'&&c <='Z')
++letter[c-'A'];
fclose(ifp);
for(i=0;i <26;++i){
if(i%6==0)
putc('\n',ofp);
fprintf(ofp,"%c:%5d ",'A'+i,letter[i]);
}
putc('\n',ofp);
fclose(ofp);
return 0;
}