c getchar help

This is a discussion on c getchar help within the C Programming forums, part of the General Programming Boards category; Hello, I need some help with getchar and compairing characters. I want to make a do while loop asking "Do ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    10

    c getchar help

    Hello, I need some help with getchar and compairing characters. I want to make a do while loop asking "Do you want to quit (Y/N)?" If yes, then the program runs again, if not, then it quits. However I have no idea how to do that in code.

    Anyone?
    Thanks in advanced

  2. #2
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    any decent 'C' book will have examples of using these library functions. Try Google and see what you find. No one here is going to 'supply' you with your homewrok coding.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    10
    Quote Originally Posted by kcpilot View Post
    any decent 'C' book will have examples of using these library functions. Try Google and see what you find. No one here is going to 'supply' you with your homewrok coding.
    Thanks for the help bud. A) I have looked around on Google, and havn't found what I want and B) this isn't homework

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >A) I have looked around on Google, and havn't found what I want
    Then I'd wager that either your search strings or your expectations need some adjustment.

    >B) this isn't homework
    That doesn't change the fact that we're not here to do your work for you. However, since this is dreadfully simple, I'll give you something to start with:
    Code:
    #include <stdio.h>
    
    int main ( void )
    {
      int ch;
    
      do {
        printf ( "Do you want to quit (Y/N)? " );
        fflush ( stdout );
        ch = getchar();
      } while ( ch != 'Y' );
    
      return 0;
    }
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getchar() problem
    By jlharrison in forum C Programming
    Replies: 6
    Last Post: 01-25-2006, 02:49 PM
  2. getchar buffer size
    By oncemyway in forum C Programming
    Replies: 3
    Last Post: 08-02-2005, 01:49 AM
  3. getchar() problem from K&R book
    By anemicrose in forum C Programming
    Replies: 13
    Last Post: 04-05-2004, 12:06 AM
  4. help with getchar lol
    By Taco Grande in forum C Programming
    Replies: 5
    Last Post: 03-18-2003, 09:25 PM
  5. Can anybody take a look at this?
    By TerryBogard in forum C Programming
    Replies: 10
    Last Post: 11-21-2002, 01:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21