编写一个求字符串中非字母字符个数的函数?
#include
#include
int alph,digit,space,others;
void count(char str[]);
void main(void)
{
char text[80];
printf("\n输入字符串:\n");
gets(text);
printf("字符串是:");
puts(text);
strcat(text,"\n");
alph=0;
digit=0;
space=0;
others=0;
count(text);
printf("\n%d字母,%d数字,%d空格,%d其它字符\n",alph,digit,space,others);
}
...全部
#include
#include
int alph,digit,space,others;
void count(char str[]);
void main(void)
{
char text[80];
printf("\n输入字符串:\n");
gets(text);
printf("字符串是:");
puts(text);
strcat(text,"\n");
alph=0;
digit=0;
space=0;
others=0;
count(text);
printf("\n%d字母,%d数字,%d空格,%d其它字符\n",alph,digit,space,others);
}
void count(char str[])
{
int i;
for(i=0;str[i]!='\n';i++)
{
if((str[i]>='a'&&str[i]='A'&&str[i]='0'&&str[i]<='9')
digit++;
else if(str[i]==' ')
space++;
else
others++;
}
}。
收起