...一串字符(以回车键结束最多80个字符)统计其中数字字母和空格_百度知 ...

发布网友 发布时间:2024-10-23 23:02

我来回答

1个回答

热心网友 时间:2024-11-16 05:51

#include <stdio.h>
#include <string.h>
#define N 100
int main(void)
{
char x[N] = {0};
int i = 0;
int alphaNum = 0;
int digitNum = 0;
int blankNum = 0;
int otherNum = 0;
printf("\nInput string:\n");
gets(x);
x[N - 1] = '\0';

i = 0;
do
{
if (isalpha(x[i]))
{
++alphaNum;
}
else if (isdigit(x[i]))
{
++digitNum;
}
else if (' ' == x[i])
{
++blankNum;
}
else
{
++otherNum;
}
++i;
} while ('\0' != x[i]);
printf("alphaNum = %d, digitNum = %d, blankNum = %d, otherNum = %d\n", alphaNum, digitNum, blankNum, otherNum);
return 0;
}

Outcome:

Input string:
sd13,.op098?
alphaNum = 4, digitNum = 5, blankNum = 0, otherNum = 3
Input string:
123ff gdf;/?
alphaNum = 5, digitNum = 3, blankNum = 2, otherNum = 3

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com