Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

func_ptr.c : Please code in C Task Overview Task-1: Your first task is to complete the comparer function in the func-ptr.c file present in the

image text in transcribed

func_ptr.c :

image text in transcribedimage text in transcribedimage text in transcribed

Please code in C

Task Overview Task-1: Your first task is to complete the comparer function in the func-ptr.c file present in the provided source code. The details of this assignment are provided in the lab3.pdf slides. Task-2: Write a program that takes a single character 'O', '1', '2', '3") from the user as input, and based on the character it performs the following operation (on two pre-defined integers): 'O' - add '1'- subtract '2' - multiply '3' - divide '4' - exit program **Please note that you are not allowed to use any conditional statements (e.g. if-else, switch-case, goto etc.) in your program. You must insert your code for this task in the task2.c file included in the lab template. Run task2 using the command./func_ptr from the command prompt ** 1 2 3 #include #include #include #include 3 4 5 6 #include "process.h" #include "util.h" 7 8 9 #define DEBUGO // change this to 1 to enable verbose output 10 11 12 13 14 15 /** * Signature for an function pointer that can compare * You need to cast the input into its actual * type and then compare them according to your * custom logic */ typedef int (*Comparer) (const void *a, const void *b); 16 17 18 19 20 21 /** * compares 2 processes * You can assume: Process ids will be unique No 2 processes will have same arrival time */ * 22 23 * 24 35 36 int main(int argc, char *argv[]) { 37 38 39 40 41 if (argc "); fflush(stdout); return 1; } 42 43 44 45 46 47 48 49 50 51 52 53 /****** *****/ /* Parse the input */ /******* *****/ FILE *input_file = fopen(argv[1], "r"); if (!input_file) { fprintf(stderr, "Error: Invalid filepath "); fflush(stdout); return 1; } 54 55 Process *processes = parse_file(input_file); 56 57 58 /******* *****/ /* sort the input */ /******** *****/ Comparer process_comparer = 59 60 &my_comparer; 61 62 63 #if DEBUG for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

3. Is IBMs program really a mentoring program? Why or why not?

Answered: 1 week ago