本题要求实现一个函数,统计给定字符串中英文字母、空格或回车、数字字符和其他字符的个数。

#include <stdio.h>
#define MAXS 15

void StringCount( char s[] );
void ReadString( char s[] ); /* 由裁判实现,略去不表 */

int main()
{
char s[MAXS];

ReadString(s);
StringCount(s);

return 0;

}

/* Your function will be put here /
void StringCount(char
s) {
int num = 0, uletter = 0, lletter = 0, blank = 0, other = 0;
for (; *s != '\0'; s++) {
if ((*s >= '0') && (*s <= '9')) {
num++;
}
else if ((*s >= 'a') && (*s <= 'z')) {
lletter++;
}
else if ((*s >= 'A') && (*s <= 'Z')) {
uletter++;
}
else if (*s == ' ') {
blank++;
}
else {
other++;
}
}
printf("% % % % %", uletter, lletter, blank, num, other);
}
(我运行不了,是哪里有问题,应该怎么更改)

s是字符串的首地址,建议你把字符串看成一个字符数组来编程,像你的s应该是运行不了的,应该改成(s+i),i的值根据字符变化