9

Making projects with C on a Windows Machine in College - Works Perfectly
Trying them on my Linux machine at home - errors on 20 lines

Comments
  • 2
    Did you use conio.h or Windows API? Windows specific things aren't portable.
  • 1
    @Fast-Nop Those are understandable. But I had most errors on getch()
  • 3
    @HAliPunjabi and where is getch() declared? In conio.h usually.
  • 3
    @Fast-Nop you learn something new everyday
  • 4
    Try this on Linux as replacement:

    #include <stdio.h>
    #include <termios.h>

    static struct termios old_term, new_term;

    /* initialise new terminal i/o settings*/
    static void initTermios(int echo)
    {
    tcgetattr(0, &old_term); /* grab old terminal i/o settings */
    new_term = old_term; /* make new settings same as old settings */
    new_term.c_lflag &= ~ICANON; /* disable buffered i/o */
    new_term.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
    tcsetattr(0, TCSANOW, &new_term); /* use these new terminal i/o settings now */
    }

    /* Restore old terminal i/o settings */
    static void resetTermios(void)
    {
    tcsetattr(0, TCSANOW, &old_term);
    }

    /* Read 1 character - echo defines echo mode */
    static char getch_(int echo)
    {
    char ch;
    initTermios(echo);
    ch = getchar();
    resetTermios();
    return ch;
    }
  • 3
    If you're on Windows 10, you can use WSL to use the gcc compiler. That's what I do
Add Comment