Question: 1. Write getfloat(), the floating-point analog of getint(). 2. What type does it return as its function value? Code: #include #include #define SIZE 5 int

1. Write getfloat(), the floating-point analog of getint().

2. What type does it return as its function value?

Code:

#include #include

#define SIZE 5

int getch(void); void ungetch(int); int getint(int *pn); // write getfloat() function signature here

int main(void){ int n, i; float array[SIZE]; for (n=0; n

// write getfloat() function here

int getint(int *pn) { int c, sign; while( isspace(c=getch()) ) ; if( !isdigit(c) && c !=EOF && c != '+' && c != '-' ){ ungetch(c); /* it's not a number */ return 0; } sign = (c == '-') ? -1 : 1; if (c == '+' || c == '-') c = getch(); for (*pn =0; isdigit(c); c = getch() ){ *pn = 10 * *pn + (c - '0'); } *pn *= sign; if (c != EOF) ungetch(c); return c; }

#define BUFSIZE 100

char buf[BUFSIZE]; int bufp =0;

/* get the next character, either from standard input or from the buffer (of character's that we placed 'back on' the buffer) */ int getch(void){ return (bufp > 0) ? buf[--bufp] : getchar(); }

/*populate the local buffer with characters you meant to 'put back' b/c you read too far*/ void ungetch(int c){ if (bufp >= BUFSIZE) printf("ungetch: too many characters "); else buf[bufp++] = c; }

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!