Compile Error
/in/foo.c: In function 'printstr': /in/foo.c:21:1: error: expected ';' before '}' token } ^ /in/foo.c: In function 'main': /in/foo.c:28:5: warning: 'gets' is deprecated [-Wdeprecated-declarations] gets(s); ^~~~ 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__; ^~~~
代码
#include <stdio.h>
#include <ctype.h>
#define N 100
void
printstr(char *p)
{
while (!((*p == ' ') || (*p == '\0')))
{
if (!isalpha(*p))
{
if (isalpha(*(p + 1)))
;
else
break;
}
putchar(*p);
p++;
}
putchar('\0')
}
int
main()
{
char s[N+1], *p, *maxp, *cmp;
int max = 0;
gets(s);
p = s;
cmp = s;
for (int i=0;; p++)
{
if (isalpha(*p))
i++;
if (isspace(*p))
{
if (i > max)
{
max = i;
maxp = cmp;
}
cmp = p + 1;
i = 0;
}
if (*p == '\0')
{
if (i > max)
{
max = i;
maxp = cmp;
}
break;
}
}
printstr(maxp);
return 0;
}