Analog of conio.h

143 Views Asked by At

How can I replace conio.h? Unlike other similar functions, it does not require pressing Enter. Are there any analogues from the standard library?

#include <conio.h>
#include <stdio.h>

int main(void)
{
    char c;
    unsigned i = 0;

    while (1) {
        c = getch();
        printf("%d - %c", i, c);
        ++i;
    }

    return 0;
}
1

There are 1 best solutions below

0
igroglaz On

it does not require pressing Enter

NCurses doesn't require pressing Enter too. This is your code based on NCurses which allows that:

#include <ncurses.h>

int main(void) {  
    char c;
    unsigned i = 0;

    initscr();
    noecho();

    while (1) {
        c = getch();
        printw("%d - %c", i, c);
        ++i;
    }

    endwin();
    return 0;
}

To compile don't forget to include "-lncurses", eg:

gcc main.c -lncurses -o main.exe