08/01/21 18:36:29
>>391
#include <stdio.h>
#include <string.h>
int main()
{
int i = 0, max = -1, max_i = -1;
char buf[200], *p, *tmp[100];
printf("単語を入力してください:");
fgets(buf, sizeof(buf), stdin);
sscanf(buf, "%s", buf);
for (p = strtok(buf, ","); p != NULL; i++)
{
int len = strlen(p);
if (max < len)
{
max = len;
max_i = i;
}
tmp[i] = p;
p = strtok(NULL, ",");
}
printf("最長文字列は%s", tmp[max_i]);
return 0;
}