Question: Main Driver File Provided: #define INSTRUCTOR_FILE #ifdef INSTRUCTOR_FILE #include #include #include #define Elements(arrayDesig) (sizeof(arrayDesig)/sizeof((arrayDesig)[0])) void SwapObjects(void *pa, void *pb, size_t size); int main(void) { //
CZASE1 (4 points - Program) Exclude any existing source code files that may already be in your IDE project and add a new one. naming it C2A5E1_Swap Objects.c. Also add instructor-supplied source code file C2A5E1_main-Driver.c. Do not write a main function! main already exists in the instructor-supplied file and it will use the code you write. File C2A5E1_Swap Objects.c must contain a function named Swapobjects. Swapobjects syntax void Swapobjects(void *pa, void *pb, size_t size); Parameters: pa - a pointer to one of the objects to be swapped pb - a pointer to the other object to be swapped size - the number of bytes in each object Synopsis: Swaps the objects in pa and pb. Return: void Do not use any kind of looping statement. Do not call any function that is not from the standard library If Swapobjects dynamically allocates memory it must also free it before returning. All dynamic allocation results must be tested for success/failure before the memory is used. If allocation fails an error message is output to stderr and the program is terminated with an error code. Submitting your solution Send both source code files to the assignment checker with the subject line C2A5E1_ID, where ID is your 9-character UCSD student iD. See the course document titled "How to Prepare and Submit Assignments" for additional exercise formatting, submission, and assignment checker requirements. Hints: 1. Merely swapping pointers pa and pb does not swap the objects to which they point 2. The only case where dynamically-allocated memory is freed automatically is when a program exits. Good programming practice dictates that dynamically-allocated memory always be explicitly freed by the program code as soon as it is no longer needed. Relying upon a program exit to free it is a bad programming practice
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
