Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


getch() , how to use it in Unix

Hi guys and gals,

i have this code:



  • nugentnugent Member Posts: 87
    you're getting the errors because you didn't link to the curses library when you compiled your program. Try:

    gcc program.c -o program -lcurses

    I'm not sure that your program will work because you have to initalise ncurses etc...

    Try this:

    #include // This include stdio.h

    int main()
    initscr(); // Initalise the ncurses library
    cbreak(); // option to disable buffering etc.
    noecho(); // disable the echoing of keystrokes
    printw("Enter Password: "); // print some text to the screen
    refresh(); // update the screen, so the text is displayed
    char pass[25]; // a place to store the text
    getstr(pass); // get text until newline or carriage return
    endwin(); // close ncurses library

    printf("You entered: %s
    ", pass); // print what the user typed to stdout

    return 0;

    compile with:

    gcc prog2.c -o prog2 -lncurses

    for more a tutorial on using the ncurses library see

Sign In or Register to comment.