Thread: regetting characters

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    115

    regetting characters

    Hi Guys.

    When i use a while loop to scan in characters for instance
    Code:
    while ( (ch=getchar()) != EOF ) {
    	if ( ch == '\n' ) {
             	do this;
    		if ( (ch=getchar()) == '\n' ) {
    			do that;
    		}
    	}
    }
    what i basically want to do is check the character 1 ahead but then reclaim it back instead of losing that character.

    How can i do this?
    Im not after an array implementation.

    Cheers!
    there are only 10 people in the world, those who know binary and those who dont

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    102
    Can you specify your problem a bit clearly.
    Saravanan.T.S.
    Beginner.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    115
    >> what i want to do is just peek at the next character thats it but if use getchar() then it doesnt work because the character i peek at doesnt return

    isnt ungetc() used for files though?

    cheers!
    there are only 10 people in the world, those who know binary and those who dont

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    115
    hmm clever.

    Dont have to think about ungetc() now.

    Thanks Salem
    there are only 10 people in the world, those who know binary and those who dont

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  3. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  4. How do you check how many characters a user has entered?
    By engstudent363 in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 06:05 AM
  5. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM