Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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) { //
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)
{
// Create some test arrays whose elements will get swapped.
int iArray[] = {0x5555, 0xAAAA};
int iArrayCopy[Elements(iArray)];
struct xyz {char c; double d;};
struct xyz sArray[] = {{'0', 1.234}, {'Z', 5.678}};
struct xyz sArrayCopy[Elements(sArray)];
// Copy initialized arrays into uninitialized arrays.
memcpy((void *)iArrayCopy, (void *)iArray, sizeof iArray);
memcpy((void *)&sArrayCopy, (void *)&sArray, sizeof sArray);
// Swap elements in test arrays.
SwapObjects((void *)&iArray[0], (void *)&iArray[1], sizeof *iArray);
SwapObjects((void *)&sArray[0], (void *)&sArray[1], sizeof *sArray);
// Test if swaps worked.
if (iArray[0] != iArrayCopy[1] || iArray[1] != iArrayCopy[0] ||
sArray[0].c != sArrayCopy[1].c || sArray[1].c != sArrayCopy[0].c ||
sArray[0].d != sArrayCopy[1].d || sArray[1].d != sArrayCopy[0].d)
{
fprintf(stderr, "SwapObjects failed ");
return EXIT_FAILURE;
}
else
printf("SwapObjects succeeded ");
return EXIT_SUCCESS;
}
#endif
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