Write a code fragment to perform the specified task; remember, it's a fragment, so you don't have to show the #include statements or main(), but you should write proper C code that could be compiled and run correctly.

1. Write a function int* sortRemoveDuplicated(int input[5][2], int *num_unique_values); to sort a multi-dimensional integer array input of a fixed size 5 by 2, remove duplicated values, update num_unique_values and return the unique sorted values as an 1D array, which is dynamically allocated in the function.

Example

int input[5][2] = { {2, 3}, {2, 3}, {2, 3}, {1, 2}, {5, 4} };
int num_unique_values = 0;
int* output = sortRemoveDuplicated(input, &num_unique_values);
for (int i = 0; i < num_unique_values; ++i) printf("%d ", output[i]);

It should print 1 2 3 4 5.

2. Complete the below function bool readLine(FILE* fp, char** line, int* array_size); that reads a line from a file given by the file pointer fp, stores the line into the C string *line, and updates the array size array_size if the array size of *line has changed. Your implementation should meet the following requirements:

  • If *line is NULL, your function should use malloc to allocate enough memory.
  • If *line is not NULL and *array_size is not large enough to store the line, you should use realloc to resize the C string.
  • *array_size should be updated to reflect the array size of the character array.
  • The C string *line must be null-terminated.
bool readLine(FILE* fp, char** line, int* array_size) {
// temp buffer, assuming a line has at most 1024 characters
char temp[1024];
if (fgets(temp, 1024, fp)) {
// TODO: temp contains the line, your tasks are:
// 1. Handle the dynamic memory allocation for *line,
// 2. Update *array_size if necessary
// 3. Copy values from temp to *line
// Note: line is a pointer to a c-string, when you
// allocate memory, think carefully which
// variable you need to use
// Write your code below
return true;
}
return false;
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.