20 likes | 140 Views
ENEE150 QUIZ 2 Spring 2012, Section 0202. You are writing a program which contains two modules, file1.c and file2.c, and a header file, header.h . The two .c modules are printed below. . f ile1.c. #include " header.h " int n1=0; int main() { int op, answer;
E N D
ENEE150 QUIZ 2 Spring 2012, Section 0202 You are writing a program which contains two modules, file1.c and file2.c, and a header file, header.h. The two .c modules are printed below. file1.c #include "header.h" int n1=0; int main() { int op, answer; printf("Enter non-zero integer and operation code: \n"); scanf("%i %i", &n1, &op); answer = compute(op); if(answer==INVALID_OPERATION) printf("INVALID\n"); else printf("answer = %i\n", answer); } file2.c #include "header.h" #define INVALID_OPERATION 0 int compute(int op) { if (op==1) return(n1*n1); else if(op==2) return(n1+n1); else return INVALID_OPERATION; }
1. In the box below, write the necessary header.h file for the code to compile and run properly. header.h Assume header.h, file1.c, and file2.c, and an input file, input.txt, all reside in the current directory. 2. Write the UNIX command that will compile the program, re-name the executable to quiz2, and enables the code to be debugged using GDB. 3. Write the UNIX command that will run the program with input.txt as the input, and redirect the output to a file called my.output.txt