You can try opening /dev/tty, but it doesn't necessarily exist, if your program run from the environment with no tty.
/dev/tty
Maybe isatty or /dev/tty could be useful to you.