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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post by answerhappygod »

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 1
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 1 (392.59 KiB) Viewed 18 times
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]
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply