Public feed #378678

Unnamed

public text v1 · immutable
Raw Edit
·published 2007-03-02 17:59 UTC
rendered paste body
struct output
{
        int freq;
        char *fname;
};


void print_search(Node *head, char **filenames, char *word) {
    Node *cur = head; int count; int j;
    int i; struct output **outputarray= NULL;

    while(cur != NULL) {
        if (strcmp(cur->word,word)==0){
                for(i = 0; i < MAXFILES; i++) {
                        if(filenames[i] != NULL) {
                        outputarray = (struct output **)realloc(outputarray, (count + 1) * sizeof(struct output *));
                        outputarray[count] = (struct output *)malloc(sizeof(struct output));
                        outputarray[count]->freq=cur->freq[i];
                        outputarray[count]->fname=filenames[i];
                        count++;
                        }
                }
        }
        cur = cur->next;
    }

   qsort(outputarray, count, sizeof(*outputarray), cmpr);
for(j=0; j<count; j++)
printf("%8d\t%s\n", outputarray[j]->freq, outputarray[j]->fname);

}