Summary: In this assignment, you will develop a program which loads data from a file and lets a console user navigate and use that data in meaningful ways.
You will develop a program that loads student, course, and grade data from a text file, then allows the user to perform simple queries on that data through a command line interface. The intention of this assignment is to familiarize you with reading data from files, allocating and using dynamically defined 1D and 2D arrays, and further developing your understanding of structs and pointers.
This document is separated into four sections: Background, Requirements, Data File, Running the Program, and Submission.
For this assignment, you will develop a program to import and handle course data stored in a text file. Your program must:
Points for this assignment are divided amongst the following requirements:
Your program is required to read from a text file which contains a description of a set of students and courses that need to be imported into your program. The data is structured as follows: see image.
The example data used above is provided with the assignment, annotated and not, for you to test your program. It is assumed that every student has a grade for every assignment in every course.
Since the data is stored as an ASCII text file, all values can be read from the file using the function fscanf( FILE * stream, const char * format, ). Some helpful resources to understand how this function works can be found at:
Similarly, for some of the functionality your program is expected to support, you will need to be able to query the terminal user for menu selections. This requires that you use the function scanf( const char * format, ). The provided code has several examples of this function in action but you may find the following resources helpful:
It is suggested that you compile and run this program from the terminal. In Ubuntu based systems, the terminal can be opened with the shortcut CTRL+ALT+t. After the terminal opens, you can perform the following steps to run the program:
1. You will start in your root directory. Navigate to the directory containing your source code and text data with the commands cd, ls, .., etc If you are unfamiliar with this process and these commands, refer to the related instructional materials provided in the course shell.
2. Once in the correct directory, we want to compile BaseReader.c. To do this we will execute the GCC compiler suite on the source file. The simplest command to do so is "gcc BaseReader.c - o reader", which will compile the file BaseReader.c and save the execute output as 'reader'.
3. Normally, to run the file we have built, we just need to enter "./reader". The dot slash means look for a file in the current folder. However, this program requires the name of the file containing our text data so we need to offer that somehow. With this code in particular, the author has chosen to use 'getopt', a function that lets you use options as a means of passing in information or flags. To run the program, we will type ./reader -d simple-data.txt.
To read more about getopt (you will need it in the next assignment, too) you might find the following resources helpful: