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, ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Location
    Sydney, Australia
    Posts
    40

    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.

    Thanks,
    TV

  2. #2
    Registered User
    Join Date
    Dec 2005
    Posts
    134

    Thumbs up

    Hi,

    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.
    S_ccess is waiting for u. Go Ahead, put u there.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Location
    Sydney, Australia
    Posts
    40
    Quote Originally Posted by maven
    Hi,

    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.

    Cheers,
    TV

  4. #4
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Quote Originally Posted by maven
    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).
    Also Microsludge....

    I hear Dev-C++ also has something called conio.h but is is not based on Borland/MS

    Your instructor needs to brush up on the standards, definitely.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    > Your instructor needs to brush up on the standards, definitely.
    Unfortunately, his instructor is a clueless moron who doesn't give a rats-ass so long as someone keeps paying a wage.
    Newbie Question - fflush(stdin) & fpurge(stdin) on Mac and PC

    It's not helped by other clueless noobs who keep on insisting that fflush(stdin) etc are standard C either.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Feb 2006
    Location
    Sydney, Australia
    Posts
    40
    Quote Originally Posted by Salem
    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.

    OK, </dead horse flogging>

    Thanks,
    TV

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    12
    Yes I have a similar problem. I am trying to clear the screen, however my compiler (Dev-C++) Does not support conio.h so I can not use clrscr()

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    dwk

    Seek and ye shall find. quaere et invenies.

    "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


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Check out the last clear screen option (Windows Console Option) in the FAQ:
    FAQ > How do I... (Level 1) > Clear the screen?

    And there's also a gotoxy() here:
    FAQ > How do I... (Level 2) > gotoxy() in a Windows Console

    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie Question - fflush(stdin) & fpurge(stdin) on Mac and PC
    By tvsinesperanto in forum C Programming
    Replies: 34
    Last Post: 03-11-2006, 11:13 AM
  2. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 03:48 AM
  3. Display ANSI graphics in C from TheDraw?
    By Ash1981 in forum C Programming
    Replies: 2
    Last Post: 12-30-2005, 01:37 AM
  4. mac dvd rom region code
    By lightatdawn in forum Tech Board
    Replies: 3
    Last Post: 03-07-2003, 12:52 PM
  5. Mac programming?
    By Luigi in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 02-07-2003, 08:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21