Menu

conio.h / conio.c

John Brake
2003-07-13
2012-09-26
  • John Brake

    John Brake - 2003-07-13

    At the risk of annoying people with yet another conio non-standard C question, I'll keep fire extinguisher at hand and venture forth...

    What I'm running:
    Win 98 SE with latest updates;
    Dev-Cpp 4.9.8.1 (downloaded 10 July) with DevPaks:
      GNU C Reference
      Dev-C++ Help File
      Dev-C++ Map file
      Console Level GDI
    Updates: everthing vUpdate 1.616 offered me (including vUpdate 1.617)

    What I'm after:
    Very simple graphics capabilities, similar to Borland's BGI from the old Turbo C.  I need this all in a nice IDE that is nice, easy to use... and Free! :)

    Why:
    I'm teaching a course in introductory programming at High School, Grade 11.  The course is being converted from Turing (a simple teaching language loosely based on Pascal) into C.  We use simple graphics to make the basic concepts of selection and repetitoin easier to handle and master.  If I get into lots of setup and code to do the graphics, I will lose my students.  (The Free! part is great -- the schools in my province are very starved for cash.  I've been given a budget of zero).

    My background:
    APL programmer since 1986.  Gotta love arrays!
    C programmer from 1986-1988, using MS QuickC and Borland TurboC nothing since.
    Turing teacher since 1997
    Familiar with the basic languages: Fortran, BASIC, COBOL, PL/1, etc.

    My problem:
    I've followed the threads and FAQs about doing the BGI-like graphics, but I'm running into a bizarre snag.  Oddly, I can't get clrscr() to be accepted in my code:

    /* straight from the CLGDI sample setup, EXCEPT that I've added in the clrscr() call and the #include <conio.h>  Take those out, it runs.
    */
    #include <winbgim.h>
    #include <conio.h>        // my addition

    int main()
    {
         initwindow(640,480); //open a 640x480 graphics window
         clrscr();                  // my addition
          setcolor(WHITE); 
        circle(320,240,99); //Draw a circle
        floodfill(320,240,WHITE);
        setcolor(LIGHTBLUE);
        circle(320,240,100);
         getch();   //wait for user to press a key
         closegraph();        //close graphics window
         return 0;
    }

    The error:

    [Linker error] undefined reference to `clrscr'

    My analysis:
    1)  FAQ states to link in the library conio.o.  Unfortunately, this doesn't seem to exist with the version of Dev-Cpp that I have.
    2)  Threads that I have read in the forum state that I should compile conio.c and use the object file from there.  Unfortunately, that appears to fail, as I obtain the following errors:
    107 C:\Dev-Cpp\include\conio.c
    [Warning] type mismatch with previous implicit declaration
    76 C:\Dev-Cpp\include\conio.c
    [Warning] previous implicit declaration of `gotoxy'
    107 C:\Dev-Cpp\include\conio.c
    [Warning] `gotoxy' was previously implicitly declared to return `int'

    [Linker error] undefined reference to `WinMain@16'

    //

    It's been a long time since I've worked in C, but it's slowly coming back.  Just trying to get past the trials of tribulations of learning this package.

    Any help would be appreciated.

    As an aside, is there in existence, an add-on to get context-sensitive help (like TurboC had the pop-up help window with all the functions detailed and examples).  I've gotten the GNU C Reference DevPak, but I've noticed that "if" doesn't seem to be in there, and searching for a function is a bit of a chore.  Anything faster and simpler for my students?

    Thank you (and hoping the fire extinguisher is unnecessary).

    Regards,
    John Brake

     
    • Anonymous

      Anonymous - 2003-07-13

      In my experience, the conio.h file that has been dupplied with Dev-C++ does not match the conio.c file also supplied. I was going to check, but I have a recent clean install, and conio.h is missing. I only have conio.c.

      I suggest that you create your own header or modify your existing one, declaring all the functions in conio.c with the correct prototypes.

      As a quick fix, just to see it this will work at all, simply add the line:

      extern void clrscr() ;

      At the top of the file wher you are using the function. This will satisfy the compiler, and the linker will tell you if the fuction does not exist, and if not they you have nott correctly linked the conio.o, or you have a broken version.

      Clifford

       
    • John Brake

      John Brake - 2003-07-16

      Clifford:

      Thank you for your kind reply -- sorry to have not responed earlier (went camping with family).

      (Beating head into wall)  Sometimes the simple yet indirect solution is best -- I should have thought of it earlier...

      "conio.o" does not exist in the installation package that I recently downloaded for Dev-Cpp 4.9.8.0 and the update to 4.9.8.1.  This file contains the code needed to link with the project in order to use the functions (as I read in the FAQ and as you also pointed out).

      No conio.o = no linking.

      Solution:  Go to an older version of Dev-Cpp and get the file by installing the older version, then dumping the old version.

      Simple.  Elegant.  Works!

      There was no need for the "extern void clrscr();" code -- the fault was in not having the library as object code.

      Ah... the longing for simple "jot-dot" and reading right-to-left in APL!

      Again, thank you very much.  Hopefully, I won't have any other problems.

      Regards,
      John

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.