Question
This builds on the program you wrote in the preceding module, so use that as a starting place for this project. In this module we:
This builds on the program you wrote in the preceding module, so use that as a starting place for this project. In this module we: Read the struct from the acars.bin file into an array. (You may use a dynamically-allocated array or a static one) Sort the array (using qsort ( )) so that it comes out in order of destination airport code, with the date and time formatted into a human-readable string.
Output the sorted array as a text file Print out each distinct destination airport code, along with a count of the number of times it occurs in the file. Use the C standard library function qsort ( ) to sort your array of structs. You will find that the sorting is key to simplifying the task of counting destination airport codes. The key to using qsort ( ) is a compare ( ) function you code that makes a decision of which of a pair of elements is greater everytime it is called. This function gets called over and over again from qsort ( ) until the array ends up in ascening order by the struct element you specify.
The C standard library provides functions for converting a POSIX time into a time struct, and subsequently into a human readable string as well. Use that to get human-readable formattting for the date-time stamp read from the binary file. Now use the C standard library qsort ( ) function to sort the array on either origin or destination airport code.
With the array sorted, write a function that takes the array as a parameter, and performs the following algorithm to count how many instances of each code exist. Set count to 0 Get a code from the array. For now, call it currCode. While you've not come to the end of the array begin Get the next code from the array. Call it nextCode If the nextCode == currCode, then add 1 to count else output code and count, set currCode to nextCode, set count to 0 end
Current code
#includeStep 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