CSC161 2011S Imperative Problem Solving

Laboratory: Pointers to Functions


Prerequisites: Sorting.


a. Log in to your MathLAN workstation. (Of course, you've probably already done that if you're reading this laboratory.)

b. Create a directory for this lab. I'd suggest Labs/FunctionPointers.

c. Make copies of these files. (Cross your fingers that I did not make a mistake in transcription.)

d. Pull out your K&R.

e. Figure out how to put everything into an executable.

f. Review the code in the various files.


Exercise 1: Reverse Sorting

Do K&R 5.14 on p. 121. That problem reads

Modify the sort program to handle a -r flag, which indicates sorting in reverse (decreasing) order. Be sure that -r works with -n.

Exercise 2: Case-Insensitive Sorting

Do K&R 5.15 on p. 121. That problem reads

Add the option -f to fold upper and lower case together, so that case distinctions are not made during sorting; for example, a and A compare equal.

For Those with Extra Time

Do K&R 5.16 on p. 121. That problem reads

Add the -d (directory order) option, which makes comparisons only on letters, numbers, and blanks. Make sure that it works in conjunction with -f.



Tuesday, 9 November 2010 [Samuel A. Rebelsky]

Monday, 18 April 2011 [Samuel A. Rebelsky]


Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Mon Apr 18 10:36:46 2011.
The source to the document was last modified on Mon Apr 18 10:36:43 2011.
This document may be found at
A PDF version of this document may be found at

Samuel A. Rebelsky,

Copyright © 2010 Samuel A. Rebelsky. This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License. To view a copy of this license, visit or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.