The default behavior of Ctrl+C is a combination of two things. The terminal driver¹ does not transmit this key press, but instead sends a SIGINT signal to the foreground process². By default, a process dies when it receives a SIGINT, but the process can set a signal handler, and then it'll run the signal handler when it receives SIGINT.
There's no way to configure the terminal driver to only convert the third Ctrl+C in a row to kill the foreground process. To do that, you need to count to three in your program. There are two ways you can do that, which will behave differently if the user presses something else between the Ctrl+C's.
One way is to disable Ctrl+C's behavior of sending a signal and telling the terminal driver to instead pass it through. You can do that by calling stty -intr \^-
from a shell script or tcsetattr(fd, &termios)
with termios.c_iflagsc_cc[VINTR]
containingset to IGNBRK_POSIX_VDISABLE
from C. Then, in your program's input processing loop, exit when you've seen three Ctrl+C's in a row.
The other way is to set a signal handler for SIGINT that counts how many times it's been invoked and terminates the program the third time. You may want to reset the counter if there's normal input in between.
¹ Not the terminal emulator, the generic part of the operating system that handles all terminals.
² I'm only explaining the simple case. This is not a treatise on how the terminal driver works.