473,387 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problem in using ungetch( )

15
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:
Expand|Select|Wrap|Line Numbers
  1. /******** Program for Read_Input Function**********/
  2.  
  3. # include <stdio.h>
  4. # include <ctype.h>
  5. # include <conio.h>
  6. # include "rpn.h"
  7. char in[10];
  8. char c;
  9.  
  10. read_input(char in[10])
  11.  
  12.     {
  13.  
  14.     int i;
  15.         c=getchar();
  16.             in[0]=c;
  17.             in[1]='\0';
  18.  
  19.         if (c==' '||c=='\t')
  20.  
  21.         while ((c=getchar())==' '||c=='\t');
  22.  
  23.         if(isdigit(c))
  24.         {
  25.         i=1;
  26.  
  27.         while (isdigit(c=getchar()))
  28.             in[i++]=c;
  29.             in[i]='\0';
  30.         if (c!=EOF)
  31.             printf("Value of c before Ungetch= %d\n",c);
  32.             ungetch(c);
  33.  
  34.         return NUMBER;
  35.             }
  36.  
  37.         if(isalpha(c))
  38.  
  39.             return ERROR_ALPHA;
  40. return c;
  41.     }
  42. /****************************************/
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
Apr 5 '07 #1
3 1831
JosAH
11,448 Expert 8TB
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.
The ungetch() function is part of the conio stuff which doesn't use the streams
used by the stdio library. You should use the ungetc() function instead; it will
put back the last character read in the input stream.

kind regards,

Jos
Apr 5 '07 #2
cworld
15
The ungetch() function is part of the conio stuff which doesn't use the streams
used by the stdio library. You should use the ungetc() function instead; it will
put back the last character read in the input stream.

kind regards,

Jos
Thankyou Jo for your quick response.
but still i m getting error:
************************************************** *
error C2660: 'ungetc' : function does not take 1 parameters stack.cpp
************************************************** *
Actually i am taking input from keyboard so it should return character to the keyboard, but it does not work.

any idea?

cworld
Apr 5 '07 #3
JosAH
11,448 Expert 8TB
but still i m getting error:
************************************************** *
error C2660: 'ungetc' : function does not take 1 parameters stack.cpp
************************************************** *
Actually i am taking input from keyboard so it should return character to the keyboard, but it does not work.

any idea?
Yep, I have an idea: the ungetc() function takes one parameter which is the
character to put back in the stream, exactly as your compiler's diagnostic
message tried to tell you.

kind regards,

Jos
Apr 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Aaron Prohaska | last post by:
I have just run into a problem where I have a page that posts back to itself to execute code, except when the page does the post back it somehow executes code that is in our home page for the site....
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
5
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: hakimks | last post by:
You are provided with a sample C programs: calc.c, which implements a reverse polish notation calculator. Study it carefully. This program uses a stack (of course!) but the stack implementation is...
5
by: Shana | last post by:
I have created one header file calc.h and had saved it in INCLUDE directory that has following declaration: #define NUMBER '0' void push(double) double pop(void) int getop(char) int...
2
by: cworld | last post by:
when i use getch , then it reads the data from the keyboard but it does not display it on screen as in the case of getchar(). So should i use ungetch() or some thing else. but the program executes...
3
by: kalar | last post by:
I can't understand how ungetch works. I read an explanation on kernighan and ritchie book but i can't understand.Can anyone give me a simple example?? Also, should i include any header file expect...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.