题目描述
用指针统计字符串中英文字母、数字的个数
输入一行字符,用指针统计字符串中英文字母和数字(字符串中只有英文字符和数字)主要代码已经给出,请补充缺少的部分。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define Maxsize 10000
int main()
{
char *p;
int sum1=0,sum2=0;
p=(char *)malloc(sizeof(char)*Maxsize);
scanf("%s",p);
while(*p)
{
/*******************************
请在该部分补充缺少的代码
********************************/
}
printf("%d %d\n",sum1,sum2);
return 0;
}
输入
一行字符串
输出
统计值
样例输入
abcdefghi123456789
样例输出
9 9
来源
答案:
if(('A'<=*p&&*p<='Z')||('a'<=*p&&*p<='z'))
sum1++;
if('1'<=*p&&*p<='9')
sum2++;
p++;
1:字符的数字与数字的区别 '1'和1;
2:while(*p)??是什么意思?