Hello, if you could do this in C, that would be great.
Create files
Read data file from command line arguments.
Data file has pairs of (cityname, zipcode).
Kalamazoo 49007
Kalamazoo 49009
Albert 13666
Create in-memory index arrays:
- One for city name and ftell position of that key in output file, sorted by city name.
- Another for zipcode and ftell position of that key in output file, sorted by zip code.
Main loop:
- Read city zip pair.
- Get location where you are going to write it in the output file using ftell.
- Write to output file using fprintf and make sure there is white space between city and zip, and white space after the zip.
- Insert key (city or zip) into the proper array sorted along with the start location in the output file.
End main loop.
After the loop, write the two index files to their own files with key location pairs.
Close files.