Question: Write a program to read given comma separated file and use C structures to store and display the data. Write a program to read given

Write a program to read given comma separated file and use C structures to store and display the data. Write a program to read given comma separated file, then sort given fields, and write sorted data into new file. Introduce the make utility. Modify the program listing.c to read the input file listings.csv and write two new functions that will sort the data based on the host_name and price. You can perform the following steps in the C program: Use any sorting algorithm to sort by the keys host_name and price separately. Make sure when you sort on any given attribute that you rearrange the entire structure. For example, if you are sorting the whole list by host_name then you need to change the order of structures based on the host_name. If you like, you can use the qsort function provided by the C library for sorting. Here is an example from the man page on how to use qsort function: qsort.c or qsort2.c. A even better example can be found here: bsearch.c. After each sort step, display the contents of the sorted structure. Test your program to ensure that the output is correctly sorted based on host_name and price. You can use the small input file tiny.csv to debug and test your program. listing0.c is as follows: /* Sample program to read a comma separated file into a structure and display the array of structures */ #include #include #include #define LINESIZE 1024 struct listing { int id, host_id, minimum_nights, number_of_reviews, calculated_host_listings_count,availability_365; char *host_name, *neighbourhood_group, *neighbourhood, *room_type; float latitude, longitude, price; }; /* create a struct, initialize it, and return it */ struct listing getfields(char* line){ struct listing item; /* Note: you have to pass the string to strtok on the first invocation and then pass NULL on subsequent invocations */ item.id = atoi(strtok(line, ",")); item.host_id = atoi(strtok(NULL, ",")); item.host_name = strdup(strtok(NULL, ",")); item.neighbourhood_group = strdup(strtok(NULL, ",")); item.neighbourhood = strdup(strtok(NULL, ",")); item.latitude = atof(strtok(NULL, ",")); item.longitude = atof(strtok(NULL, ",")); item.room_type = strdup(strtok(NULL, ",")); item.price = atof(strtok(NULL, ",")); item.minimum_nights = atoi(strtok(NULL, ",")); item.number_of_reviews = atoi(strtok(NULL, ",")); item.calculated_host_listings_count = atoi(strtok(NULL, ",")); item.availability_365 = atoi(strtok(NULL, ",")); return item; } /* display the struct */ void displayStruct(struct listing item) { printf("ID : %d ", item.id); printf("Host ID : %d ", item.host_id); printf("Host Name : %s ", item.host_name); printf("Neighbourhood Group : %s ", item.neighbourhood_group); printf("Neighbourhood : %s ", item.neighbourhood); printf("Latitude : %f ", item.latitude); printf("Longitude : %f ", item.longitude); printf("Room Type : %s ", item.room_type); printf("Price : %f ", item.price); printf("Minimum Nights : %d ", item.minimum_nights); printf("Number of Reviews : %d ", item.number_of_reviews); printf("Calculated Host Listings Count : %d ", item.calculated_host_listings_count); printf("Availability_365 : %d ", item.availability_365); } int main(int argc, char* args[]) { struct listing list_items[22555]; char line[LINESIZE]; int i, count; count = 0; /* read input till end of input */ while (fgets(line, LINESIZE, stdin) != NULL){ list_items[count++] = getfields(line); } /* display structure */ for (i=0; i

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!