08.01.2023 Views

Learn to Program with C_ Learn to Program using the Popular C Programming Language ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9 ■ Searching, Sorting, and Merging

void printResults(FILE *out, int max, char list[][max],

int freq[], int n) {

fprintf(out, "\nWords Frequency\n\n");

for (int h = 0; h < n; h++)

fprintf(out, "%-15s %2d\n", list[h], freq[h]);

} //end printResults

Suppose the file passage.txt contains the following data (from If by Rudyard Kipling):

If you can dream—and not make dreams your master;

If you can think—and not make thoughts your aim;

If you can meet with Triumph and Disaster

And treat those two impostors just the same...

If you can fill the unforgiving minute

With sixty seconds’ worth of distance run,

Yours is the Earth...

When Program P9.4 was run with this data, it produced the following output:

Words

Frequency

aim 1

and 4

can 4

disaster 1

distance 1

dream 1

dreams 1

earth 1

fill 1

if 4

impostors 1

is 1

just 1

make 2

master 1

meet 1

minute 1

not 2

of 1

run 1

same 1

seconds 1

sixty 1

the 3

think 1

269

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!