CS19002 Programming and Data Structures Laboratory Spring 2009, Section 2

Assignment 8
(Dynamic memory management)

Part 1   [Credit: 50%]

The file names.txt stores a list of names. The file begins with the number of names that follow. Each name is then supplied in a single line. For simplicity, assume that there are no spaces in a name. (Notes on File I/O)

Store the names in this file in a two-dimensional character array. Use a dynamically allocated array. Each row stores one name as a string and must be allocated an amount of memory just sufficient to store that name along with the terminating null character.

Part 2   [Credit: 50%]

Write a function to sort the two-dimensional array of names prepared in Part 1. The sorting should be done with respect to the standard dictionary ordering. You may use any sorting algorithm. However, to keep matters simple, I recommend the use of bubble sort.

You may use string library functions (like strlen(), strcpy() and strcmp()).

Run your program on the input file names.txt and print the sorted array.

Submission site | Lab home | Course home | My home