#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
char line[256], lastcanon[256], lastword[256], *word;
strcpy(lastcanon, "*Undefined*");
for (;;) {
if ((gets(line) == NULL) || ((word = strchr(line, '=')) == NULL)) break;
*word++ = '\0'; // word is the current word just read, line is the canonical key for it
if (strcmp(line, lastcanon) == 0) {
// We have at least one match
printf("%s", lastword);
for (;;) {
printf(" %s", word);
if ((gets(line) == NULL) || ((word = strchr(line, '=')) == NULL)) break;
*word++ = '\0';
if (strcmp(line, lastcanon) != 0) break; // next word
}
printf("\n");
}
strcpy(lastcanon, line);
strcpy(lastword, word);
}
return(0);
}