有一篇文章,共有3行文字,每行有8…

来源:互联网 发布:淘宝旺旺号怎么查看 编辑:程序博客网 时间:2024/05/16 05:22
有一篇文章,共有3行文字,每行有80个字符。要求分别统计出其他英文大写字母、小写字母、数字、空格以及其他字符的个数。
#include <stdio.h>
#include <stdlib.h>
void main()
{
char ch[3][80];
int SLetter = 0,CLetter = 0,Num = 0,Space = 0,Other = 0;
for(int i = 0;i<3;i++)
{
gets(ch[i]);
for(int j = 0;j<80;j++)
{
if(ch[i][j]>=48&&ch[i][j]<58)
{
Num++;
}
else if(ch[i][j]>=65&&ch[i][j]<91)
{
CLetter++;
}
else if(ch[i][j]>=97&&ch[i][j]<123)
{
SLetter++;
}else if(ch[i][j]==' ')
{
Space++;
}else Other++;
}//for
}//for

printf("\nSLetter = %d\nCLetter = %d\nNum = %d\nSpace =%d\nOther = %d",SLetter,CLetter,Num,Space,Other);

for(i = 0;i<3;i++)
{
for(int j  = 0;j<8;j++)
printf("%c",ch[i][j]);
printf("\n");
}


}

另外遇到一些问题:当要用二维数组分拆一维数组输出的问题。
0 0
原创粉丝点击