How to restore the normal terminal when Ctrl+C is pressed?

Viewed 208

I have created a digital clock program. I use this cmd

printf("\033[?25l");
            // Hiding the cursor

but when I stop the program with Ctrl+C the terminal cursor is still hidden. How do I solve this problem and restore the cursor after Ctrl+C?

1 Answers
        static volatile int continueRunning = 1;// 
        void intHandler(int dummy) {
             printf("\033c");// clear the console
             printf("\e[?25h");//To re-enable the cursor
                 continueRunning = 0;
        }
    
    
    
    int main(int argc, char **argv) // you can use like this int main(int argc, char *argv[]) { /* ... */ }
    {
        signal(SIGINT, intHandler);
      
        
            while (continueRunning) {
/// to continuue your code
Related