C How to return screen to normal after curses program ends

I'm still new to C and ncurses. I was asked to do an assignment that involved making a multithreaded pong game. The game runs fine and ends with the correct lossing conditions but upon termination my terminal is all messed up. I get no echo, so I have to type stty echo to get that back, even then the terminal behaves strangely.

My end function is the following:

void wrap_up(){

    curs_set(1);
    clear();
    endwin();
    refresh();
}

Here is a screenshot. How do I fix it?

enter image description here


Solution 1:

Remove refresh after endwin. Calling refresh after endwin causes the program to go back into the curses mode.