#include #include "freq-list.h" #define MAXLINESIZE 1024 char buffer[MAXLINESIZE]; char filename[MAXLINESIZE] = "STANDARD_INPUT"; freq_list fl = fl_empty; void print_entry(char *word, int freq) { printf("%s %s %d\n", word, filename, freq); } int main() { char *nl; while (fgets(buffer, MAXLINESIZE, stdin) != NULL) { if (!isspace(buffer[0])) { /* new file */ fl_foreach(print_entry, fl); /* out with the old */ fl = fl_destroy(fl); /* no harm doing this first time through */ sscanf(buffer, "%s", filename); continue; } /* else new word occurence in same file */ if (nl = index(buffer, '\n')) *nl = '\0'; fl = fl_insert(buffer+1, fl); } fl_foreach(print_entry, fl); /* No need to destroy the last list */ }