Question: Please help with this macro, getting bugs in mine and cant get around them, thank you! Main Driver File Provided: #define INSTRUCTOR_FILE #ifdef INSTRUCTOR_FILE #include
Please help with this macro, getting bugs in mine and cant get around them, thank you!
Main Driver File Provided:
#define INSTRUCTOR_FILE
#ifdef INSTRUCTOR_FILE
#include
#include
#include
#include "C2A4E2_StorageMap5D.h"
#define D_A 2
#define D_B 3
#define D_C 4
#define D_D 5
#define D_E 6
int main(void)
{
int ix0, ix1, ix2, ix3, ix4;
int foo[D_A][D_B][D_C][D_D][D_E];
double bar[D_A][D_B][D_C][D_D][D_E];
long big[D_E][D_D][D_C][D_B][D_A];
float deal[D_E][D_D][D_C][D_B][D_A];
// seed random # generator
srand((unsigned)time(NULL));
// store all values before testing any
for (ix0 = 0; ix0
for (ix1 = 0; ix1
for (ix2 = 0; ix2
for (ix3 = 0; ix3
for (ix4 = 0; ix4
{
foo[ix0][ix1][ix2][ix3][ix4] = rand();
bar[ix0][ix1][ix2][ix3][ix4] = rand() + rand() / 321.0;
}
for (ix0 = 0; ix0
for (ix1 = 0; ix1
for (ix2 = 0; ix2
for (ix3 = 0; ix3
for (ix4 = 0; ix4
{
big[ix0][ix1][ix2][ix3][ix4] = rand();
deal[ix0][ix1][ix2][ix3][ix4] = rand() + rand() / 123.0F;
}
// Test all stored values.
for (ix0 = 0; ix0
for (ix1 = 0; ix1
for (ix2 = 0; ix2
for (ix3 = 0; ix3
for (ix4 = 0; ix4
{
if (StorageMap5D((int *)foo, ix0, ix1, ix2, ix3, ix4,
D_B, D_C, D_D, D_E) != foo[ix0][ix1][ix2][ix3][ix4])
{
fprintf(stderr, "Error: foo[%d][%d][%d][%d][%d] ",
ix0, ix1, ix2, ix3, ix4);
return EXIT_FAILURE;
}
if (StorageMap5D((double *)bar, ix0, ix1, ix2, ix3, ix4,
D_B, D_C, D_D, D_E) != bar[ix0][ix1][ix2][ix3][ix4])
{
fprintf(stderr, "Error: bar[%d][%d][%d][%d][%d] ",
ix0, ix1, ix2, ix3, ix4);
return EXIT_FAILURE;
}
}
for (ix0 = 0; ix0
for (ix1 = 0; ix1
for (ix2 = 0; ix2
for (ix3 = 0; ix3
C2A4E2 (6 points - Program) Exclude any existing source code files that may already be in your IDE project and add a new one. naming it C2A4E2_StorageMap5D.h. Also add instructor-supplied source code file C2A4E2_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 C2A4E2_Storage Map5D.h must contain a macro named StorageMap5D. StorageMap5D syntax (never actually prototype a macro): StorageMap5D(ptr, idxo, idx1, idx2, idx3, idx4, dimi, dim2, dim3, dim) Parameters: ptr-a pointer to the first element of a block of memory to be used as a 5-dimensional array idxo, idx1, idx2, idx3. idx4 - the indices of the desired element of the array dimi, dim2, dim3, dim - the rightmost 4 dimensions of the array (dimo isn't needed) Synopsis: implements the storage map equation for a 5-dimensional array of arbitrary type having arbitrary dimension values. It may be used to access the elements of any existing 5-dimensional array of any type and sufficient size, or in the general case may be used to access any arbitrary block of memory of sufficient size as if it were a 5-dimensional array. Value: the element specified by the macro's 2nd through 6th arguments. Example: For an arbitrary array of any type originally declared as type test(SZ_A][SZ_B][SZ_C] [SZ_D] [SZ_E]; or any block of dynamic memory allocated by type *test - (type *) malloc((SZ_A SZ_B. SZ_C * SZ_D * SZ_E) * sizeof(type)) the expression StorageMap5D((type *)test, 68, 73, 22, 58, 49, SZ_B, SZ_C, SZ_D, SZ_E) would access the following element of the array or the dynamically-allocated memory block. [68][73][22][58] [49] for (ix4 = 0; ix4
{
if (StorageMap5D((long *)big, ix0, ix1, ix2, ix3, ix4,
D_D, D_C, D_B, D_A) != big[ix0][ix1][ix2][ix3][ix4])
{
fprintf(stderr, "Error: big[%d][%d][%d][%d][%d] ",
ix0, ix1, ix2, ix3, ix4);
return EXIT_FAILURE;
}
if (StorageMap5D((float *)deal, ix0, ix1, ix2, ix3, ix4,
D_D, D_C, D_B, D_A) != deal[ix0][ix1][ix2][ix3][ix4])
{
fprintf(stderr, "Error: deal[%d][%d][%d][%d][%d] ",
ix0, ix1, ix2, ix3, ix4);
return EXIT_FAILURE;
}
}
--ix0;
--ix1;
--ix2;
--ix3;
--ix4;
if (StorageMap5D((long *)big, ix0 + 1 - 1, ix1 + 2 - 2, ix2 + 3 - 3,
ix3 + 4 - 4, ix4 + 5 - 5, D_D + 4 - 4, D_C + 3 - 3, D_B + 2 - 2,
D_A + 1 - 1) !=
big[ix0][ix1][ix2][ix3][ix4])
{
fprintf(stderr, "Error 2: big[%d][%d][%d][%d][%d] ",
ix0, ix1, ix2, ix3, ix4);
return EXIT_FAILURE;
}
printf("Assignment 4 Exercise 2: No errors detected! ");
return EXIT_SUCCESS;
}
#endif
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
