C语言 怎么实现多组测试?

输入一串字符,统计这串字符里的字母个数,数字个数,空格字数以及其他字符(最多不超过100个字符)
我编的程序只能测试一组,怎么修改可以测试多组?
#include <stdio.h>
int main()
{
char c;
int letters=0,space=0,digit=0,others=0;
{
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("%d %d %d %d\n",letters,digit,space,others);
}
return 0;
}

第1个回答  2009-11-18
#include <stdio.h>
#include<string.h>
int main()
{
char c,s[100];
int i;
int letters=0,space=0,digit=0,others=0;
while(gets(s)!=NULL){
for(i=0;i<strlen(s);i++){
c=s[i];
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
}
printf("%d %d %d %d\n",letters,digit,space,others);
}
return 0;
}本回答被提问者采纳
第2个回答  2009-11-18
#include <stdio.h>
int main()
{
char c;
int letters=0,space=0,digit=0,others=0,mun,i;
{
printf("请输入要测试组数");
scanf("%d",&mun);
for(i=0;i<mun;i++)
{
printf("开始输入下一组");
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("%d %d %d %d\n",letters,digit,space,others);
}
}
return 0;
}
相似回答