Question: Extend the following program so that it uses getchar ( only ) to read and interpret floating point literals #include #define SIZE 50 // assume
Extend the following program so that it uses getchar (only) to read and interpret floating point literals
#include
#define SIZE 50 // assume no more than 50 literals in input
int main(){
int c;
int value;
int resu[SIZE];
int negative;
int index = 0;
int i;
value = 0;
c = getchar();
while ( c != EOF){
if (c=='-'){
negative=1;
}
else if (c == ' ' || c == ' ')
{
if(negative==1){
value = -value;
}
resu[index] = value;
index++;
value=0;
negative=0;
}
if(c >= '0' && c <= '9')
value = value*10+(c-'0');
c = getchar(); // read next
}
printf("-------- ");
for(i=0;i printf("%d\t%d ", resu[i],resu[i] *2); return 0; } Sample Inputs/Outputs: (download dont copy/paste - the input file input2E.txt) red 306 % a.gcc lab2E.c -o lab2 red 306 % lab2 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
