Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Develop an ANSI-C program that reads user information from the standard inputs, and outputs the modified version of the records. #include ..... #define SIZE 10
Develop an ANSI-C program that reads user information from the standard inputs, and outputs the modified version of the records. #include7.2 Implementation Download file lab4fgets.c and start from there. Note that the program uses loop to read inputs (from standard in), one input per line, about the user information in the form of name age rate, where name is a word (with no space), age is an integer literal, and rate is a floating point literal. See sample input below. uses fgets () to read in a whole line at a time. As discussed earlier, since the input contains space, using scanf("%s", inputArr) does not work here, as scanf stops at the first blank (or new line character if no space). Consequently, if user enters Joe 2 2.3, only Joe is read in. As mentioned in this week's class, in order to read a whole line of input which may contain blanks, you can use scanf("%[^ ]s", inputsArr), or, depreciated function gets (inputsArr), but a much more common approach is to use function fgets (). Both these functions are declared in stdio.h. fgets (inputsArr, n, stdin) reads a maximum of n characters from stdin (Standard input) into array inputsArr. The program should, after reading each line of inputs, if it is not "exit", output the original input using printf and fputs. Notice that since fgets reads in a' ' at the end of input, printf does not need in the formatting string. then create a char array resu for the modified version of the input. In the modified version of input, the first letter of name is capitalized, age becomes age + 10, and rate has 100% increases with 3 digits after decimal point, followed by the floor and ceiling of the increase rate. The values are separated by dashes and brackets as shown below. then output the resulting string resu. continue reading input, until a line of exit is entered. Hints: When fgets reads in a line, it appends a new line character at the end (before \0). Be careful about this when checking if the input is exit. To tokenize a string, consider sscanf To create resu from several variables, consider sprintf. If you use math library functions, be aware that the return type is double. Also remember to compile the program using -lm flag of gcc. 7.3 Sample Inputs/Outputs: red 118 $ a.out Enter name, age and rate (or "exit"): sue 22 33.3 sue 22 33.3 sue 22 33.3 Sue-32-66.600-[66,67]..... #define SIZE 10 #define SIZE2 40 int main(int argc, char *argv[]) { char input[SIZE2]; char name[SIZE]; .... char resu[SIZE2]; printf("Enter name, age and rate (or \"exit\"): "); fgets(input, 40, stdin); while (...) { //output original input using two functions. printf("%s", input); // no needed fputs(input, stdout); .... .... /* use fgets to read again */ } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started