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
Step: 1
Get Instant Access to Expert-Tailored Solutions
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