问答题
以下程序的功能是利用指针统计一个字符串中字母、空格和制表符、数字及其他字符的个数。
#include<stdio.h>
#include<string.h>
main()
{int alpha,space,digit,other;
char *p,s[100];
alpha=space=digit=other=0;
printf("Please input string:\n");
gets(s);
for(p=s;*p!="\0";p++)
if(______)
alpha++; //统计字母个数
else if(______)
space++; //统计空格和制表符的个数
else if(______)
digit++; //统计数字个数
else
other++;
printf("alpha:%d space:%d digit:%d other:%d\n",alpha,space,digit,other);
}
【参考答案】
*p>="A"&&*p<="Z"||*p>="a"&&*p<="z"
*p=" "||*p=="\t"......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)