C语言程序设计
大一新生求助编写一个函数,输入一行字符,将字符串中最长的单词输出。
2017-11-29 09:59
2017-11-29 16:39
程序代码:#include<stdio.h>
#include<string.h>
int main()
{
int len, maxlen = 0;
char maxword[512];
char buf[]="hello boy this is heimass";
char *temp = NULL;
temp = strtok(buf, " ");
while (temp) {
len = strlen(temp);
if (len > maxlen) {
strcpy(maxword, temp);
maxlen = len;
}
temp = strtok(NULL," ");
}
printf("%s\n", maxword);
return 0;
}
2017-11-29 17:01

2017-11-30 10:38