发布网友 发布时间: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: