Thread: Usage of ungetch funtion.

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    4

    Smile Usage of ungetch funtion.

    Hi All,

    I have been working with java from a long time, I have never worked with C programming language...I am from electronics background so was not in touch with these languages...I have started learning C language these days...and I have found it awesome...atleast I will get something to write as a code...not like java where every thing is provided in packages...I have one question I am searching for the usage of ungetch function, I have found definition everywhere but I couldn't found an example which can explain the usage. Kindly help me on this. I hope to get a positive reply from you guys and also kindly let me know a good ID for C. Thanks!!

    Regards,
    Pawan Chopra.

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    It's not a standard C function and I've never seen nor used it.
    That's all I can tell you.
    If I had to guess, I'd say it puts a character back into the stdin stream.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  3. #3
    Complete Beginner
    Join Date
    Feb 2009
    Posts
    312
    Citing from the manpage of ungetc(3):

    int ungetc(int c, FILE *stream);

    [...]

    ungetc() pushes c back to stream, cast to unsigned char, where it is available for subsequent read operations. Pushed-back characters will be returned in reverse order; only one pushback is guaranteed.

    [...]

    Conforming To
    C89, C99.
    The Linux manpages are pretty good. If you need help with common C functions, use "linux man <function>" in Google/linux.die.net or, if you're working in a Unix environment, type "man <function>" in the terminal.

    ungetch() may be anything, definitely not standard. Most commonly, this is some sort of Windows stuff or the ungetch() function from the (n)curses library. Same trick as above also applies here.

    Greets,
    Philip
    Last edited by Snafuist; 03-09-2009 at 07:08 AM.
    All things begin as source code.
    Source code begins with an empty file.
    -- Tao Te Chip

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    ungetch is not ungetc, though the idea is similiar.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Complete Beginner
    Join Date
    Feb 2009
    Posts
    312
    I should stop writing my posts incrementally and instead start a new post...

    Greets,
    Philip
    All things begin as source code.
    Source code begins with an empty file.
    -- Tao Te Chip

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reduce CPU usage
    By patrick22 in forum Windows Programming
    Replies: 9
    Last Post: 07-10-2009, 02:13 PM
  2. Net cpu usage of pthreads?!
    By mynickmynick in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2008, 07:59 AM
  3. Memory usage and memory leaks
    By vsanandan in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 05:45 AM
  4. Calculating CPU Usage
    By vitaliy in forum Linux Programming
    Replies: 3
    Last Post: 08-21-2005, 09:38 AM
  5. Win2K Limiting CPU Usage?
    By drdroid in forum Tech Board
    Replies: 4
    Last Post: 03-31-2004, 02:08 PM