1. The C code below is designed to ask the user to enter up to ten integers but stop if a zero is entered. It should the
Posted: Wed Apr 27, 2022 5:05 pm
1. The C code below is designed to ask the user to enter up to ten integers but stop if a zero is entered. It should then print out the number of integers read in. This code is saved in a file called readint.c. #include <stdio.h> int main(void) { int i = 0, myData [10]; 00 OWNP 2 3 4 5 6 7 8 9 10 11 12 13 14 15 for (int i = 0; i < 10; i++) { printf ("Enter an integer: "); scanf("%d", &myData); if (myData == 0) break printf ("Number of integers read is %d \n", i); return 0; } a) Show the modifications needed to replace the scanf() function in the code above with the fgets() and sscanf() functions. [4] b) Write a Makefile for this program that uses at least two automatic Make variables. The executable that is built should be named readint. [4] c) Why would you create a phony target in a Makefile? Write a phony target which removes any object files created during compilation of readint.c. [3] d) When the program is compiled with gcc, the following errors are reported: $ gcc --std=c99 -O readint readint.c readint.c: In function 'main': readint.c:12:5: error: expected ';' before 'printf' printf ("Number of integers read is %d\n", i); readint.c:15:1: error: expected declaration or statement at end of input } Identify the two errors in the C code: What lines do these errors appear on, and how would you fix them? [4]