#include<stdio.h> #include<string.h> int main() { char str[100]; char *p; p=&str; scanf("%s",&str); while(*p!='\0') { /******************************* 请在该部分补充缺少的代码 ********************************/ } return 0; }
时间: 2023-07-06 17:37:43 浏览: 114
好的,这是一个字符串遍历的问题,我们需要在while循环中依次遍历字符串中的每个字符,并统计其中的数字字符个数、字母字符个数和其他字符个数。
以下是C语言代码:
```c
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
char *p;
int digit = 0, letter = 0, other = 0;
p = str;
scanf("%s", &str);
while (*p != '\0') {
if (*p >= '0' && *p <= '9') {
digit++;
} else if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z')) {
letter++;
} else {
other++;
}
p++;
}
printf("digit:%d\nletter:%d\nother:%d", digit, letter, other);
return 0;
}
```
我们使用了指针`p`指向字符串`str`首地址,并使用`scanf`函数输入字符串。在while循环中,我们使用`if`语句判断当前字符的类型,并统计数字字符个数、字母字符个数和其他字符个数。最后,我们使用`printf`函数输出统计结果即可。