vasile ion
vasile ion

Reputation: 9

Ncurses in C, implement backspace

I'm working on a project to build wordle game with ncurses library. At this moment, I'm stuck because I try to implement backspace and it didn't work.

Here is my code:

#include <ncurses.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char **argv) {
    initscr();
    noecho();
    curs_set(0);
    int Y_Max, X_Max;
    getmaxyx(stdscr, Y_Max, X_Max);
    WINDOW *win = newwin(Y_Max / 2 + 1, X_Max / 4, Y_Max / 4, X_Max / 4);
    box(win, 0, 0);
    mvwprintw(win, 2, 25, "WORDLE");
    wgetch(win);
    char s[100];
    for (int j = 0; j < 6; j++) {
        WINDOW *chenar = newwin(1, 5, Y_Max / 4 + 4 + j, X_Max / 4 + 25);
        box(chenar, 0, 0);
        int i = 0;
        while (i < 5) {
            s[i] = wgetch(win);
            int coo = getparx(chenar), coo2 = getpary(chenar);
            if (s[i] != 127 && s[i] != KEY_BACKSPACE && s[i] != '\b') {
                wprintw(chenar, "%c", s[i]);
                wrefresh(chenar);
                i++;
            } else {
                wmove(chenar, coo2, coo);
                clrtoeol();
                wrefresh(chenar);
            }
        }
        wgetch(chenar);
    }
    cbreak();
    refresh();
    endwin();
    return 0;
}

When I run, I type every character and when I pressed backspace it doesn't clear my line. I hope you can help me. Thanks!

Upvotes: 0

Views: 102

Answers (0)

Related Questions