用isalpha isspace isdigit ispunct函数就可,但是为什么我用isspace输出的空格不对???
#include <ctype.h>
#include <string.h>
int main()
{
char str[1000];
int yingwen = 0;
int kongge = 0;
int num = 0;
int other = 0;
while(fgets(str,sizeof(str),stdin))
{
for(int i = 0;i < strlen(str);i++)
{
if(isalpha(str[i]))
yingwen++;
//else if(isspace(str[i]))
else if((str[i]) == ' ')
kongge++;
else if(isdigit(str[i]))
num++;
else if(ispunct(str[i]))
other++;
}
printf("%d\n",yingwen);
printf("%d\n",kongge);
printf("%d\n",num);
printf("%d\n",other);
memset(str,0,sizeof(str));
}
return 0;
}