Question: Extend the program, so that it uses getchar (only) to read and interpret floating point literals. Use getchar() to read inputs (from standard in) until

Extend the program, so that it uses getchar (only) to read and interpret floating point literals.

Use getchar() to read inputs (from standard in) until EOF is read. The input contains floating point literals and integer literals separated by one blanks or new line characters. The program interprets each literal and put into an float array. When end of file is reached, the program prints out the value of each float as well as the value multiplied by 2, as shown in sample output below.

Assume all floating point literals are valid float/double or int literals (both 2.3, 5, .4 are considered valid). There are no negative numbers.

Should not use other input IO functions such as scanf(), fgets(). Only getChar() is allowed to read input. (So have to read char by char.)

Should not use other library function such as atoi(), atol(), atof(), strtol(), strtoul(). (So have to convert manually)

input2E.txt:

3.25 24.54 4.323 4.54 .4 1 0.29

Sample Inputs/Outputs:

red 306 % a.gcc lab2E.c -o lab2E

red 306 % lab2E

2.3 4.56 43.3 43 5.3

.3 1.2

^D

--------

2.3000 4.6000 4.5600 9.1200 43.3000 86.6000 43.0000 86.0000 5.3000 10.6000 0.3000 0.6000 1.2000 2.4000 red 307 % cat input2E.txt

3.25 24.54

4.323 4.54 .4 1 0.29 red 308 % lab2E < input2E.txt

--------

3.2500 6.5000

24.5400 49.0800

4.3230 8.6460

4.5400 9.0800

0.4000 0.8000

1.0000 2.0000

0.2900 0.5800

red 309 %

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!