Question: Supplied Header file: #ifndef C2A5E2_TYPE_DRIVER_H #define C2A5E2_TYPE_DRIVER_H #define ELEMENTS 9 // Type to use for dynamic array elements... typedef signed char Type[ELEMENTS]; #undef ELEMENTS #endif

 Supplied Header file: #ifndef C2A5E2_TYPE_DRIVER_H #define C2A5E2_TYPE_DRIVER_H #define ELEMENTS 9 //
Supplied Header file:
#ifndef C2A5E2_TYPE_DRIVER_H
#define C2A5E2_TYPE_DRIVER_H
#define ELEMENTS 9
// Type to use for dynamic array elements...
typedef signed char Type[ELEMENTS];
#undef ELEMENTS
#endif
Supplied Driver File:
#define INSTRUCTOR_FILE
#ifdef INSTRUCTOR_FILE
#include
#include
#include
#include "C2A5E2_Type-Driver.h"
#define DIM_MAX 27
#define DIM_STEP 1
#define ROW_COUNT_START 1
#define COL_COUNT_START DIM_MAX
Type **Create2D(size_t rows, size_t cols);
void Free2D(void *p);
static int Test2D(Type **ppObj, int dim0, int dim1);
int main(void)
{
Type **ppObj;
int rows, cols, gotFailure = 0;
for (
rows = ROW_COUNT_START, cols = COL_COUNT_START;
rows 0;
rows += DIM_STEP, cols -= DIM_STEP
)
{
int failed;
// Create a 2D array of "Objects" dynamically.
ppObj = Create2D((size_t)rows, (size_t)cols);
// Test it and print the results.
failed = Test2D(ppObj, rows, cols);
// Free the array.
Free2D((void *)ppObj);
if (failed)
{
gotFailure = 1;
fprintf(stderr, "Create2D(%d, %d) failed ", rows, cols);
}
else
printf("Create2D(%d, %d) succeeded ", rows, cols);
}
if (gotFailure)
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
int Test2D(Type **ppObj, int dim0, int dim1)
{
signed char testValue;
int row, col, ix;
int error;
Type *pObj;
Type item;
// Fill up the array with known values using 2D syntax.
testValue = SCHAR_MIN;
for (row = 0; row
{
for (col = 0; col
{
// For this to work Type must be a 1D array type.
for (ix = 0; ix
{
// printf("%4d ", testValue);
ppObj[row][col][ix] = testValue;
if (testValue == SCHAR_MAX)
testValue = SCHAR_MIN;
else
++testValue;
}
}
}
// printf(" ");
// Verify the stored values using a compact pointer.
error = 0;
testValue = SCHAR_MIN;
for (pObj = (Type *)(ppObj + dim0);
pObj
{
// For this to work Type must be a 1D array type.
for (ix = 0; ix
{
// printf("%4d ", (*pObj)[ix]);
if ((*pObj)[ix] != testValue)
{
error = 1;
break;
}
if (testValue == SCHAR_MAX)
testValue = SCHAR_MIN;
else
++testValue;
}
if (error)
break;
}
// Return a success or an error code.
return error;
//lint -e{550} suppress "'item' not accessed"
}
#endif
C2A5E2 (6 points - Program) Exclude any existing source code files that may already be in your IDE project and add a new one, naming it C2A5E2_Create2D.c. Also add instructor-supplied source code files C2A5E2 Type-Driver.h and C2A5E2_main-Driver.c. Do not write a main function! main already exists in the instructor-supplied implementation file and it will use the code you write. Regarding data type Type, which is used in this exercise... Type is a typedef'd data type that is defined in instructor-supplied header file C2A5E2_Type-Driver.h Any file that uses this data type must include this header file using #include. File C2A5E2_Create 2D.c must contain functions named Create2D and Free2D. Create2D syntax: Type **Create2D(size_t rows, size_t cols); Parameters: rows - the number of rows in the 2-dimensional pointer array Create2D will create cols - the number of columns in the 2-dimensional pointer array Create2D will create Synopsis: Creates a 2-dimensional pointer array of data type Type having the number of rows and columns specified by rows and cols. All memory needed for this array is dynamically-allocated at once using a single call to the appropriate memory allocation function. If allocation fails an error message is output to stderr and the program is terminated with an error code. Return: a pointer to the first pointer in the array Free2D syntax: void Free2D(void *p); Parameters: p-a pointer to the block of memory dynamically-allocated by Create2D Synopsis: Frees the dynamically-allocated block of memory pointed to by p. Return: vold Submitting your solution Send all three source code files to the assignment checker with the subject line C2A5E2_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

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!