Question: Write a program in C to read the Listings.csv file. Declare a function, sortByHostName, that should sort the data based on hostname. Declare a function,

Write a program in C to read the Listings.csv file. Declare a function, sortByHostName, that should sort the data based on hostname. Declare a function, sortByPrice, that should sort the data based on price. After sorting, sortByPrice and sortByHostName should write the sorted array to a file. General Approach Declare a struct called 'Listing' with contains all the attributes found in 'Listings.csv'. Define a function that will take one line of the CSV file and return a 'Listing' struct with corresponding attribute values. Declare an array of the 'Listing' structs. Open the 'Listings.csv' file with the fopen() function in read-mode. Loop through each line of the 'Listings.csv' file. Feel free to use either the fgets() function or the getline() function. For each line, call the function you previously defined. Store the result in array of 'Listing' structs. In sortByHostName and sortByPrice, use the qsort() function to sort the array. Use the fopen() to open a file in write mode. Use the fputs() function or the fprintf() to write the sorted array to a file.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!