[comp.os.msdos.programmer] Reading Ctrl-C in TC++

zimmer@calvin.stanford.edu (Andrew Zimmerman) (03/22/91)

In article <4729@gumby.Altos.COM> jerry@altos.COM (Jerry Gardner) writes:
>In article <lee.669434518@chsun1> lee@chsun1.uchicago.edu (Dwight A Lee) writes:
>}I'm writing a program in the ANSI C mode of Turbo C++ 1.01, and I want
>}to be able to read control-C just like any other character.  Right now
>}I'm using getch(), but when control-C is pressed, it acts as if I
>}typed control=Break.
>}
>}Is there a way to disable this behavior and just have getch() return
>}0x03 when control-C is pressed?  I would like to do this from within
>}the program.  Or do I have to install my own... keyboard interrupt
>}somehow?  I am familiar with the concept but have never used
>}interrupts on the MS-DOS PC.
>

    I just tried the following program under Turbo C++ 1.00

main()
{
    int c;

    while((c = getch()) != 'q')
    {
        printf("%c\n",c);
    }
}
I compiled using tcc -A tst.c (-A is for ansi mode I believe)

It doesn't seem to have the same behavior that the original poster was 
upset about.  getch handles the ^c without any problem.  In fact, it
loves it when I type a ^c.  (a very subtle bit of humor.  Run the program) :-)

Turbo C++ also has the getcbrk and setcbrk functions that might be of use.

Is there a possiblity that it has something to do with the version of DOS?
(I'm running Zenith 3.3+)

Andrew
zimmer@calvin.stanford.edu

dougs@videovax.tv.tek.com (Doug Stevens) (03/28/91)

One of the chronic problems I've had with trapping ^C is not handling the
^C itself, but trying to find a good way to supress the printout on screen 
of the ^C character.

BIOS somehow bypasses the usual streams and outputs this directly to stdout.
About the only way I've found to supress it is to re-direct stdout to NUL,
but then sdtout can't be used for other purposes.