Accepted
/in/foo.c: In function 'main': /in/foo.c:10:5: warning: 'gets' is deprecated [-Wdeprecated-declarations] gets(str); ^~~~ In file included from /in/foo.c:1:0: /usr/include/stdio.h:640:14: note: declared here extern char *gets (char *__s) __wur __attribute_deprecated__; ^~~~ /in/foo.c:8:20: warning: unused variable 'c' [-Wunused-variable] char str[N+1], c; ^ /tmp/ccBJkt45.o: In function `main': foo.c:(.text.startup+0xd): warning: the `gets' function is dangerous and should not be used.
代码
#include <stdio.h>
#include <ctype.h>
#define N 100
int
main(void)
{
char str[N+1], c;
int alpha = 0, num = 0, space = 0, other = 0;
gets(str);
for (char *c=str; *c != '\0'; c++)
{
if (isalpha(*c))
alpha++;
else if (isalnum(*c))
num++;
else if (isspace(*c))
space++;
else
other++;
}
printf("%d\n%d\n%d\n%d", alpha, num, space, other);
return 0;
}