Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Specification Develop an ANSI-C program that reads user information from the standard inputs, and outputs the modified version of the records. Implementation Download file lab4fgets.c

image text in transcribed
image text in transcribed
image text in transcribed
Specification Develop an ANSI-C program that reads user information from the standard inputs, and outputs the modified version of the records. 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 10). Be careful about this when checking if the input is exit. To create resu, you may want to tokenize the original input first. 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 if you run the program in our lab environment, need to compile the program using -im flag of gcc. Sample Inputs/Outputs: red 118 % a.out Enter name, age and rate: sue 22 33.3 sue 22 33.3 sue 22 33.3 Sue-32-66.600-66,67] Enter name, age and rate: john 60 1.0 john 60 1.0 john 60 1.0 John-70-2.000-(2,2] Enter name, age and rate: lisa 30 1.34 lisa 30 1.34 lisa 30 1.34 Lisa-40-2.680-[2,3] Enter name, age and rate: judy 40 3.2 judy 40 3.2 judy 40 3.2 Judy-50-6.400-[6,7] Enter name, age and rate: exit red 119 % #include #define SIZE 10 #define SIZE2 40 int main(int argc, char *argv[]) { char resu[SIZE2]; char input[SIZE2]; char name[SIZE]; printf("Enter name, age and rate (or \"exit\"): "); fgets (input, 40, stdin); while (...) { I/output original input using two functions. printf("%s", input); // no needed fputs (input, stdout); .... may need to tokenize input /* use fgets to read again */ } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+Where does the focus of labor relations lie? Is it collective

Answered: 1 week ago