September 1998
Intermediate to advanced
848 pages
20h 13m
English
Let's tackle the practical problem of sorting strings alphabetically. This task can show up in preparing name lists, in making up an index, and in many other situations. One of the main tools in such a program is strcmp(), because it can be used to determine the order of two strings. The general plan will be to read an array of strings, sort them, and print them. A little while ago, we presented a scheme for reading strings, and we will start the program that way. Printing the strings is no problem. We'll use a standard sorting algorithm that we'll explain later. We will do one slightly tricky thing; see whether you can spot it. Listing 11.25 presents the program.
/* ... |
Read now
Unlock full access