#include #include #define MAXLEN 60 int main (void) { char word[MAXLEN], longword[MAXLEN]; int wordlen; int longest = 0; int ch; ch = getchar (); while (ch != EOF) { /* First, skip anything other than letters. */ while (! isalpha (ch) && ch != EOF) { ch = getchar (); } /* Now we've got the beginning of a word. */ wordlen = 0; while (isalpha (ch)) { if (wordlen < MAXLEN-1) { /* don't want to overflow the buffer */ word[wordlen++] = ch; } ch = getchar (); } word[wordlen] = '\0'; /* finish it with a null character */ if (wordlen > longest) { longest = wordlen; strcpy (longword, word); } } /* Reached end of file. Print the answer. */ printf ("The longest word was \"%s\", which was %d characters long.\n", longword, longest); return 0; }