Why does <conio.h> not work on my Mac? Non ANSI?

This is a discussion on Why does <conio.h> not work on my Mac? Non ANSI? within the C Programming forums, part of the General Programming Boards category; Hello all,
I am currently in week 7 of an 18 week C course and, over the past several weeks, ...

Why does <conio.h> not work on my Mac? Non ANSI?

Hello all,

I am currently in week 7 of an 18 week C course and, over the past several weeks, I have had several problems with the examples given by my teacher. Some of you may remember this thread.

Once again, I have come across a situation where the example code, supplied by my teacher, works for the rest of the class (using Dev-C on Windows98 machines) but doesn't work for me (using MacOSX 10.4.5 and Xcode 2.2).

The problem stems from the header file <conio.h>. Whenever this is included in any example, Xcode throws up an error at compile time (technically, I guess it's GCC that throws up the error).

Now, true to form, my teacher absolutely insists that, like the fflush(stdin) function (see the thread I linked to above), the <conio.h> header file is completely ANSI compliant. Based on previous form, I am a bit skeptical...in the same way that the Pacific Ocean has a "bit" of water in it.

So, in the interests of clarification, can anyone tell me...

1) Whether or not <conio.h> is a standard ANSI header file?
2) What functions <conio.h> might be included for. I suspect that it might be getche() or getch() (I don't know what the difference is between those two, by the way. Any illumination would be appreciated), because whenever one or both of those pop up in an example, the <conio.h> header file is included.

you are very right about ur guess....
Because conio.h is not part of the C standard either POSIX or ANSI. It is a Borland extension, and works only with Borland compilers (and perhaps some other commercial compilers).

Besides getch() and getche(), there is one more function clrscr()which is associated with <conio.h>.

clrscr() does... Clear the screen using VT escape codes.

getch() does... This is a nonstandard function that gets a character from keyboard, does not echo to screen.

getche() does.... This is a nonstandard function that gets a character from the keyboard, echoes to screen.

beside use getchar(), if you want it to work on all compilers.
it is a standard function that gets a character from the stdin.

you are very right about ur guess....
Because conio.h is not part of the C standard either POSIX or ANSI. It is a Borland extension, and works only with Borland compilers (and perhaps some other commercial compilers).

Besides getch() and getche(), there is one more function clrscr()which is associated with <conio.h>.

clrscr() does... Clear the screen using VT escape codes.

getch() does... This is a nonstandard function that gets a character from keyboard, does not echo to screen.

getche() does.... This is a nonstandard function that gets a character from the keyboard, echoes to screen.

beside use getchar(), if you want it to work on all compilers.
it is a standard function that gets a character from the stdin.

Thank you very much for clearing this up for me. It is pretty much as I expected but it is great to have it confirmed.

It's not helped by other clueless noobs who keep on insisting that fflush(stdin) etc are standard C either.

Yes, as I've said in a couple of different places on this forum, that little nugget of disinformation set me back by several weeks while I tried to work out what the hell was what. Not only did it waste my time, it was also very stressful because it seemed to be impossible to get a definitive answer from anyone (including my teacher). In addition to that, until I worked out what was going on (thanks to the help of several very helpful posts on this forum from people who really know their stuff), I was unable to run or edit any of the example files I was given in-class because I had no idea what I was doing wrong. By the time I worked out what was what, I was at least 2 weeks behind the rest of my class and I had to put in a lot of extra work to catch up again. That was 3 weeks that I'd just as soon forget and I certainly wouldn't want to have to repeat it.

I have said all this before in other threads but it was a huge problem for me at the time and I really want to make sure that people realise what sort of damage this type of misinformation can cause for newbs who don't know any better.

If you are going to suggest something like this that is non-standard, please, PLEASE, PLEASE, at the very least, add a footnote to the effect that the method you are suggesting is non-standard and may not be portable across platforms and/or between different compilers. It's a simple and quick precaution and it may save some poor bastard, like myself, weeks of frustration and stress.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

And as tvsinesperanto has explained, these aren't portable. However it does help to have all the code in a separate function. That way if you do port to another system, you may be able to replace the code in the function with code which does the equivalent on the new system.