Clearing screen and kbhit() function

后端 未结 2 1534

I got some problems writing my snake game program. I need to make game working on linux and windows. I found some topics how to clear screen on linux and windows using the

相关标签:
2条回答
  • 2020-12-22 09:30

    On Unix-liked systems including Linux and macOS, you can use ncurses library (POSIX API). In case of Windows (or even Linux or macOS), the following code will work on ANSI terminals on any systems.

    printf("\033[2J\033[H");
    /* or */
    printf("\033[0;0f");
    
    0 讨论(0)
  • 2020-12-22 09:36

    C89 does not have terminal handling functions. Instead, you should use OS specific functions. So you need to have, say, a source file only for windows functions and another for linux. Another option is to use a cross platform library. I would choose ncurses for this task:

    http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/

    It works on any unix system, including linux and Mac OS. For windows versions, see:

    Is ncurses available for windows?

    With ncurses, you have functions like erase() and clear() to clear the screen.

    0 讨论(0)
提交回复
热议问题