Thread: please help new programmer!!!!!

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    3

    please help new programmer!!!!!

    i just need to know if there is a relatively easy way to use a "hit any key" function in my program. if anyone has any ideas i would be most grateful.

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    51
    If your compiler supports it, use getch(). It takes in a character then proceeds without the user having to press enter. Otherwise, make your menu say "press enter to continue" and use getc() or getchar().


    P.S. I think you have to include "conio.h" to use getch().

  3. #3
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    in C++ You need to have <<endl though
    example for c++:
    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main()
    {
        cout<<"Press any key to continue"<<endl;
        getch();
        cout<<endl<<"Good!"<<endl;
        return 0;
    }
    however, my C compiler doesn't support conio
    one way I did it on C (which was annoying as hell!)
    Code:
    #include <stdio.h>
    int main()
    {
        char ans[];
        printf("Do you wish to continue? [Y/N]: ");
        scanf(%c, &ans);
        printf("\n");
        if(ans[0] == "y" || ans[0] == "Y") 
        {
            goto cont;
        }
        else { return 0; }
        cont:
        // Stuff for rest of code here
        return 0;
    }
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What game programmer should I be? need some advice.
    By m3rk in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 04-20-2009, 11:12 PM
  2. Approved Nintendo Programmer for hire
    By DScoder in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 07-24-2007, 09:24 PM
  3. Replies: 8
    Last Post: 01-04-2004, 12:01 PM
  4. Me as a programmer?
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 03-31-2002, 06:19 PM
  5. I need to interview professional programmer.....please
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 01-05-2002, 02:46 PM