Hi all
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:
This function is called in the main program but again when i call this function it gets the next charater from the input. should i make a userdifine function for getch and ungetch like as given in Ritchie book chapter4. or some otherthings??
thankyou
cworld
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:
Code:
/******** 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
Comment