“Press Any Key to Continue” function in C

后端 未结 5 1342
無奈伤痛
無奈伤痛 2021-01-30 14:15

How do I create a void function that will work as \"Press Any Key to Continue\" in C?

What I want to do is:

printf(\"Let the Battle Begin!\\n\");
printf(         


        
5条回答
  •  庸人自扰
    2021-01-30 14:30

    Use getch():

    printf("Let the Battle Begin!\n");
    printf("Press Any Key to Continue\n");
    getch();
    

    Windows alternative should be _getch().

    If you're using Windows, this should be the full example:

    #include 
    #include 
    
    int main( void )
    {
        printf("Let the Battle Begin!\n");
        printf("Press Any Key to Continue\n");
        _getch();
    }
    

    P.S. as @Rörd noted, if you're on POSIX system, you need to make sure that curses library is setup right.

提交回复
热议问题