From 442a49ad5a48d417345959b903ae6a6d32d55759 Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Fri, 15 Apr 2022 15:51:30 -0500 Subject: Great C programming fun Excellent fundamentals and displine training, many tools and techniques exercises: gdb, emacs, valgrind, git --- 30_sort_lines/README | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 30_sort_lines/README (limited to '30_sort_lines/README') diff --git a/30_sort_lines/README b/30_sort_lines/README new file mode 100644 index 0000000..c5dcb2a --- /dev/null +++ b/30_sort_lines/README @@ -0,0 +1,43 @@ +For this problem, you will write a program (by modifying the provided +sortLines.c file) which sorts strings from input files. As we have not +yet covered sorting, we have provided the code that does the acutal +sorting. You can just call this function, which will sort the data. + + void sortData(char ** data, size_t count); + +The sortData function takes two arguments. The first is an array of strings. +The second is the length of that array. It will re-order the elements of the +array, such that they are sorted. + +Your task in this problem primarily centers around reading the data into +the array from the input file(s), so that it can be sorted. You will also +need to print the data after it is sorted, and free all of the memory you have allocated. + +Specifically, this program should take 0 or more command line arguments. + - If no arguments (other than its own name) are provided (argc ==1), then + your program should read from standard input, sort the lines of input, + print the results, free memory, and exit successfully. + - If 1 or more arguments are provided (argc > 1), then your program should + treat each argument as an input file name. It should open that file, + read all of the lines of data in it, sort the lines, print the results, + free the memory, and close the file. If any errors occur, your program + should print an appropriate error message and exit with EXIT_FAILURE. + If no errors occur, your program should indicate its success after processing + all of the files. + +Note that we now place *no* restriction on the length of any individual line of input. +You should therefore use the getline function to read an arbitrarily long line of +input, dynamically allocating space for it as needed. See the man page for getline +for more details. + +You should make sure your program valgrinds cleanly, including no memory leaks +before you submit it. As always, submit your code for grading. + +We've provided one simple test for you to use to test your program. Run it with: +./test.sh + +Hints: + - Don't forget to abstract code out into smaller function. In my solution, + I wrote 3 functions other than main (plus the 2 that are provided). + - Don't forget to draw pictures! They are even more important + as you use pointers more and more. -- cgit v1.2.3