#include <
stdio.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
char str[256];
puts("请输入一个长度不超过200的
字符串:");
gets(str);
int i = 0, alpha = 0, digit = 0, space = 0, spunct = 0;
for(;str[i]!='\0';i++)
{
if(isalpha(str[i]))
alpha++;
else if(isdigit(str[i]))
digit++;
else if(isspace(str[i]))
space++;
else if(ispunct(str[i]))
spunct++;
}
printf("该字符串的字母个数: %d个,数字个数: %d个,空格个数: %d个,标点个数: %d个\n",alpha,digit,space,spunct);
return 0;
}来自:求助得到的回答