#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char str[] = " you are,a.student";
char sep[] = " ,.";
char* tok = NULL;
char maxlen[20] = ""; //用来保存字符串中较长的单词
for (tok = strtok(str, sep); tok != NULL; tok = strtok(NULL, sep)){
if (strlen(maxlen) < strlen(tok)){
strcpy(maxlen, tok);
}
}
puts(maxlen);
system("pause");
return 0;
}
利用strtok输出字符串中最长的单词
最新推荐文章于 2022-09-16 16:50:52 发布