题目:输入一行字符串,统计单词、数字、空格、其他字符的个数
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int word, num, space, other;
int main(void)
{
void count(char[]);
char str[80];
printf("enter four string:\n");
scanf("%s", str);
count(str);
printf("word:%d num:%d space:%d other:%d ", word, num, space, other);
return 0;
}
void count(char str[])
{
int i;
for (i = 0; str[i] != '\0'; i++)
{
if (str[i] >= '0' && str[i] <= '9')
num++;
else if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
word++;
else if (str[i] == ' ')
space++;
else
other++;
}
}