#include <stdio.h>
#include <string.h>
void find_second_largest_word_in_string(char string[], char second_largest[]) {
char largest[16] = "";
int found_second = 0;
char* word = strtok(string, " ,.-");
while (word != NULL) {
if (strlen(word) > strlen(largest)) {
strcpy(second_largest, largest);
strcpy(largest, word);
}
else if (strlen(word) > strlen(second_largest) && !found_second) {
strcpy(second_largest, word);
found_second = 1;
}
word = strtok(NULL, " ,.-");
}
}
int main(void)
{
char string[] = "c cpp cobol c# python java";
char second_largest[16] = "";
find_second_largest_word_in_string(string, second_largest);
printf("The second largest word is: %s\n", second_largest);
return 0;
}
/*
run:
The second largest word is: cobol
*/