问题遇到的现象和发生背景
题目内容:
编写程序,输入一个字符串(字符串长度不超过300),分别统计并输出该字符串中的字母个数和数字个数。要求用指针指向这个字符串进行处理。
输入格式:
字符串
输出格式:
英文逗号分隔的2个整数,第一个整数是字母个数,第二个整数的数字个数。
输入样例:
the day the month the year 123
输出样例:
21,3
用代码块功能插入代码,请勿粘贴截图
#include<stdio.h>
#include<stdlib.h>
int main()
{
char s[300];
char* p = s;
int m = 0, n = 0;
scanf_s("%s", s, 300);;
while (*p)
{
if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' || *p <= 'Z'))
{
++m;
p++;
}
else if (*p >= 1 && *p <= 9)
{
++n;
p++;
}
else if (*p == ' ')
{
p++;
}
}
printf("%d,%d", m, n);
system("pause");
return 0;