```
2. 声明一个函数来统计不同字符的数量:
```c
void countCharacters(char* str, int* letters, int* spaces, int* digits, int* others) {
int i = 0;
char c;
*letters = *spaces = *digits = *others = 0;
while ((c = str[i++]) != '0') {
if (isalpha(c)) {
(*letters)++;
} else if (isspace(c)) {
(*spaces)++;
} else if (isdigit(c)) {
(*digits)++;
} else {
(*others)++;
}
}
}
```
在这个函数中,我们使用指针来更新传递给函数的变量。
3. 在主函数中调用这个函数,并输出结果:
```c
int main() {
char str[100];
printf("请输入一段字符串:");
fgets(str, sizeof(str), stdin);
int letters, spaces, digits, others;
countCharacters(str, &letters, &spaces, &digits, &others);
printf("字母的数量:%dn", letters);
printf("空格的数量:%dn", spaces);
printf("数字的数量:%dn", digits);
printf("其他字符的数量:%dn", others);
return 0;
}
```
在主函数中,我们首先声明一个字符串数组来存储用户输入的字符串。然后,通过调用`fgets`函数从标准输入中获取字符串。接下来,我们声明用于存储不同字符数量的变量,并调用`countCharacters`函数来计算它们的数量。最后,我们使用`printf`函数输出结果。
这样,当用户运行程序时,它将要求用户输入一个字符串,并输出字符的统计信息。
同时,一加Ace2Pro还有骁龙8Gen2处理器、1.5K屏幕等配置,放在同价位中基本挑不出什么短板了。, 冲击10万亿日元目标 保持热度也好,提升品牌格调也罢,从优衣库母公司迅销集团的角度来看,所有的动作都要为创始人定下的小目标服务。
两人一旦出演影视剧,必将奉献出佳作!这是两位实力派的艺人。,高质量承办2024年“奔跑吧·少年”吉林省百万青少年上冰雪高山滑雪、短道速滑、越野滑雪等系列活动。
截至目前,全市有5899家民营企业参与帮扶,实施兴村项目7010个,惠及3524个村。, 2023年10月,国家药监局正式命名第三批“药品法治宣传教育基地”,市市场监管局位列其中,成为云南省首个被国家药监局命名的“药品法治宣传教育基地”,也是目前全国仅有的17个国家药监局法治宣传教育基地之一。