#include
#include
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;
}
#include
#include
int main()
{
char arr[200];
int i=0;
char a;
while(a=getchar() && a!='\n')
{
arr[i]=a;
i++;
}
int x=0,y=0,g=0,h=0;
for(int j=0;j{
if(isalpha(arr[j]))
x++;
else if(isdigit(arr[j]))
y++;
else if(isspace(arr[j]))
g++;
else if(ispunct(arr[j]))
h++;
}
printf("字母有%d个,数字有%d个,空格有%d个,标点有%d个\n",x,y,g,h);
return 0;