This is the practice for function pointer, you are be required to finish a task execulator using function pointer.
Given the below struct
typedef struct{
void (*func)(void *);
void *argument;
}Task;
typedef struct{
int* arr;
int lower;
int upper;
}Data;
typedef struct{
Task **tasks;
int size;
}Task_List;
and you need to implement 5 functions to pass this practice.
func1 : void job1(void* argument); // reverse
func2 : void job2(void* argument); // minus
func3 : void job3(void* argument); // double
func4 : void initTask(Task* task, void(*func)(void*),void* argument);
func5 : void executeTasks(Task_List *task_list);
For this problem, we will give you a global array and you need to modify the value in global array with different job using function pointer
Take two simple cases for example:
case 1 : when user input lower = 0, upper = 5 and method = 0 (job1) for an array A = {1,2,3,4,5,6,7}
output: 6, 5, 4, 3, 2, 1, 7
case 2: when user input lower = 2, upper = 4 and method = 1 (job2) for an array A = {1,2,3,4,5,6,7}
output: 1, 2, -3, -4, -5, 6, 7
case 3: when user input lower = 0, upper = 0 and method = 2 (job3) for an array A = {1,2,3,4,5,6,7}
output: 2, 2, 3, 4, 5, 6, 7
main.c
function.h
T
Mi Li Ui
...
T: the number of task (2 < T < 100)
Mi: the type of job (Mi = {0, 1, 2})
Li: the lower bound of the array (0 <= Li < 25)
Ui: the upper bound of the array (Li <= Ui < 25)
Output the global array after finishing all tasks.