Due: Monday 11/08 8:00 am
GitHub Submission Link: git@github.com:mks65/13_structrw.git
- Here You will find a csv file of NYC census population values.
- The header of the file is this:
Year,Manhattan,Brooklyn,Queens,Bronx,Staten Island
- An example line of data is this:
1790,33131,4549,6159,1781,3827
- The header of the file is this:
- Your goal: write a program that will perform the following actions based on a command line argument:
-read_csv
- Read the contents of the file (this is text).
-
Store each piece of data using the following struct:
struct pop_entry { int year; int population; char boro[15]; };
- Create & write a new file containing the population data using
struct pop_entry
. This file should contain byte data.- If the file already exists, overwrite the existing one.
-read_data
- Read the contents of the data file into an array of
struct pop_entry
values. This array should be dynamically allocated based on the file size. - Display the data in human-readable format, provide a number for each data entry when displaying.
- Read the contents of the data file into an array of
-add_data
- Ask the user for new data to put into a
struct pop_entry
value. - Append that data to the end of the data file (not the csv).
- Ask the user for new data to put into a
-update_data
- Start like
-read_data
. - Then prompt the user to enter the corresponding number of an entry to modify.
- Then prompt the user for new data.
- Update the entry in the data file (not the csv).
- Start like
Sample output:
- read_csv
$ ./structrw -read_csv reading nyc_pop.csv wrote 2760 bytes to nyc_pop.data
- -read_data
- This is only the fist 11 entries, there should be 115 at the start.
$ ./structrw -read_data 0: year: 1790 boro: Manhattan pop: 33131 1: year: 1790 boro: Brooklyn pop: 4549 2: year: 1790 boro: Queens pop: 6159 3: year: 1790 boro: Bronx pop: 1781 4: year: 1790 boro: Staten Island pop: 3827 5: year: 1800 boro: Manhattan pop: 60515 6: year: 1800 boro: Brooklyn pop: 5740 7: year: 1800 boro: Queens pop: 6642 8: year: 1800 boro: Bronx pop: 1755 9: year: 1800 boro: Staten Island pop: 4563 10: year: 1810 boro: Manhattan pop: 96373
- This is only the fist 11 entries, there should be 115 at the start.
- -add_data
2020 Bronx 1390450
Was entered manually at the time of the program running.$ ./structrw -add_data Enter year boro pop: 2020 Bronx 1390450 Appended data to file: year: 2020 boro: Bronx pop: 1390450
- -update_data
- Only showing the last ffeew lines of output, but all the data should be displayed.
108
and9999 Stuy 4000
where entered manually.$ ./structrw -update_data 107: year: 2000 boro: Queens pop: 2229379 108: year: 2000 boro: Bronx pop: 1332650 109: year: 2000 boro: Staten Island pop: 443728 110: year: 2010 boro: Manhattan pop: 1585873 111: year: 2010 boro: Brooklyn pop: 2504700 112: year: 2010 boro: Queens pop: 2230722 113: year: 2010 boro: Bronx pop: 1385108 114: year: 2010 boro: Staten Island pop: 468730 115: year: 2020 boro: Bronx pop: 1390450 entry to update: 108 Enter year boro pop: 9999 Stuy 4000 File updated.