20 likes | 111 Views
ENEE150 QUIZ 2 Spring 2012, Section 0203. 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 " char n1[SIZE]; #define INVALID_OPERATION 0 int main() { int answer;
E N D
ENEE150 QUIZ 2 Spring 2012, Section 0203 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" char n1[SIZE]; #define INVALID_OPERATION 0 int main() { int answer; printf("Enter four characters separated by white spaces\n"); scanf("%c %c %c %c", &n1[0], &n1[1], &n1[2], &n1[3]); answer = compute(n1[1]); if(answer==INVALID_OPERATION) printf("INVALID\n"); else printf("answer = %c\n", toupper(n1[2])); //NOTE: Use of library ctype.h } file2.c #include "header.h" #define SIZE 4 int compute(char op) { if (op=='a') return(SIZE); else if(op == n1[3]) return(SIZE+1); 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 quiz, 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