Thread: Changing a variable

  1. #16
    Registered User
    Join Date
    Feb 2009
    Posts
    8
    I think I chose getch because it didn't require an enter press.

  2. #17
    Registered User
    Join Date
    Feb 2009
    Posts
    138
    Quote Originally Posted by laserlight
    In the first place, you would not need getchar() or getch() if you run your program from the command prompt, or use an IDE that pauses the program for you.
    that's not how getch or getchar are being used in the program? it's for real input in this case, not pausing to keep the window open.

  3. #18
    Registered User
    Join Date
    Feb 2009
    Posts
    8
    Should I use scanf instead? or fgets or something else? I have no idea.

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by matthew82
    I think I chose getch because it didn't require an enter press.
    Right, but as I noted in post #14, you do not need it at all. For more information, read How to keep a Windows console from closing.

    Quote Originally Posted by Meldreth
    that's not how getch or getchar are being used in the program? it's for real input in this case, not pausing to keep the window open.
    Of course, but in the case of "real input", I would still recommend changing to getchar(), at least for the time being.

    EDIT:
    Should I use scanf instead? or fgets or something else? I have no idea.
    getchar() should be correct, methinks.

    Frankly, Meldreth is right: your exact usage of getch() did not register when I read your code (in my defense, it is 4 a.m. and I am awake for fun), but I still would recommend that you prefer what is standard until you have acquired more knowledge of C.
    Last edited by laserlight; 02-06-2009 at 02:19 PM.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to put a check on an extern variable set as flag
    By rebelsoul in forum C Programming
    Replies: 18
    Last Post: 05-25-2009, 03:13 AM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  3. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  4. write Variable and open Variable and get Information
    By cyberbjorn in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 01:30 AM
  5. Changing variable
    By Mithoric in forum Windows Programming
    Replies: 4
    Last Post: 03-30-2004, 09:45 PM