Thread: Getch();

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Getch();


    Hello again everybody.

    I have made my first hello world:

    #include <stdio.h>

    int main(void)
    {
    printf("Hellooooo World");
    getch();

    }

    Just like the first tutorial video in C on thenewboston . org. But i get an error when i use getch();
    The problemindicater says: "Implicit declaration of function "getch" is invalid in C99". What does that mean? I just wrote precisly the same thing as Bucky does in his videos.

    Best Regards
    Mads
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Wilmington, DE
    Posts
    4
    Rep Power
    0
    getch(); requires the use of conio. So you need to #include <conio.h> at the beginning of your program.

    I've heard that getch() fell out of style, though maybe one of the more experienced programmers can confirm or deny. I personally prefer:

    cout <<endl;
    system("pause");
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    conio limits the portability of your program to windows systems and that rare installation that provides an equivalent.

    You could use
    Code:
    #include <stdio.h>
    ...
      getchar();
    But again, that's ridiculous. Change your command windows to remain open. Make sure you read all the way through
    "Applying changes to all command windows."
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo