I am making an RPN calculator in which i want to read data from input. so i used getchar( ) and able to read character by character. But when the while condition fullfill then it comes out from the loop but retain the next character read from input so i want to ungetch to the input. but it does not work. Plz help me, my code is:
Expand|Select|Wrap|Line Numbers
- /******** Program for Read_Input Function**********/
- # include <stdio.h>
- # include <ctype.h>
- # include <conio.h>
- # include "rpn.h"
- char in[10];
- char c;
- read_input(char in[10])
- {
- int i;
- c=getchar();
- in[0]=c;
- in[1]='\0';
- if (c==' '||c=='\t')
- while ((c=getchar())==' '||c=='\t');
- if(isdigit(c))
- {
- i=1;
- while (isdigit(c=getchar()))
- in[i++]=c;
- in[i]='\0';
- if (c!=EOF)
- printf("Value of c before Ungetch= %d\n",c);
- ungetch(c);
- return NUMBER;
- }
- if(isalpha(c))
- return ERROR_ALPHA;
- return c;
- }
- /****************************************/
thankyou
cworld