Assume each line of a csv file has the following format: name,age,GPA. You can assume the name is at most 50 characters, the age is
Assume each line of a csv file has the following format: name,age,GPA. You can assume the name is at most 50 characters, the age is a whole number with at most 3 digits, and the GPA is between 0.00 and 4.00 and has at most 2 digits after the decimal point (for example, 3.17). Also, you can assume that there are no more than 100 lines in the csv file.
Take a csv filename as a command line argument.
Open the csv file and use fgets to read the contents.
Store the data in an array of structures.
Write the data out to a new csv file called output.csv, with the following changes: Reverse the order of the lines. In each line, switch the positions of the age and GPA data. Add a line at the end with the first field empty, the average GPA in the 2nd field, and the average age in the 3rd field. Accuracy of averages: Two digits after the decimal point for the average GPA, and 1 digit after the decimal point for the average age.
Other than the changes above, the data in the output file should be identical to the data in the input file (exact same characters with no change in formatting, no rounding or truncating of numerical values, etc.).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started