Menu

Why many C Progs don't compile on Dev-C++

2004-11-26
2012-09-26
  • Nobody/Anonymous

    Hi...im new on C and i use Dev-C++ cause its nice
    and not so big like c++ builder 6.

    I have problem, for example this src.
    While compiling to an EXE i get many errors, so what is wrong here, do i need some plugins ?

    // #include

    void main(void)
    {clrscr();
    textcolor(3);
    cprintf("IDE-INFO v1.00\r\n\r\n");

    printf("\n\nFibonacci-Numbers\n\n");
    int a = 0;
    int b = 1;
    int i;
    int x;
    
    printf("%d ", a );
    printf("%d ", b );
    
    while(b<5000)
       {x = a;
        a = b;
        b = x + b;
        printf("%d ", b);
       }
    printf("\n\n"); system("PAUSE");
    

    }

    Thanks for now.....

     
    • Edmund Tudor

      Edmund Tudor - 2004-11-26

      "clrscr(); exists in C. It is defined in 'conio.h'. It works perfectly fine in Turbo C and Turbo C++, Borland C++. It doesn't work in Dev C++.I dont know why."

      Just because it works in Borland compilers doesn't mean it's part of the C language. Dev uses the GCC compilers which pretty much sticks to standard C/C++

      You can search the forum for clrscr to find some alternatives, this subject comes up quite often.

       
    • Nobody/Anonymous

       
    • E.Naumovich

      E.Naumovich - 2004-11-26

      'conio.h' is DOS console library. If you want to use its function in Dev-c++ with mingw32 (which is not DOS compiller at all) you must use other similar library, for example use something from here:
      http://devpaks.org/list.php?category=Text%20console

       
    • Anonymous

      Anonymous - 2004-11-26

      Note that Dev-C++ using GCC as its compiler has little (in fact nothing) to do with what libraries are available. The compiler (and the C language) and the libraries are distinct. The MinGW distribution of GCC utilises the MSVCRT.DLL that is installed with Windows. So you need to reference Micosoft's documentation at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/crthm.asp.

      If you want to know what is in the standard library, and therfore generally provided with all compilers check http://www.cppreference.com/

      The Microsoft C library is a superset of the standard library.

      Console I/O is not standard (except for the basic TTY style services provided by stdio) because systems have varying console capabilities, and the standard must run on all systems. In Win32 there is a console API, that will work with any Win32 compiler. Conio is a hangover from DOS, and even then Microsoft and Borland's conio libraries differed significantly. It is best forgotten unless you realy need to port legacy code. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/console_reference.asp for the Win32 API.

      To see how clear screen can be implemented using the console API see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/clearing_the_screen.asp.

      Clifford

       
    • Anonymous

      Anonymous - 2004-11-26

      ... and...

      You should always include the headers for the libraries you are using. That way errors can be detected by the compiler rather than the linker. The linker can only tell if a symbol you have used does not exist, whereas the compiler can check that you have used the correct number and types of parameters.

      If you include headers for libraries other than the standard library, then you also have to explicitly link the associated libraries.

      Clifford

       
    • Georhan

      Georhan - 2004-11-26

      First, why is your #include in comment ? You usually need to include headers (like <iostream>, <cstdio>) for your program to work.

      The printf() function for example is declared in <cstdio> ; cprintf() in <conio.h> ; clrscr() doesn't exists in C++, just in Pascal.

      The main function must return an integer. Both following declarations are accepted by the compiler :

      int main(void) ;
      int main(int, char **) ;

      textcolor() will surely need a little #include too...

      Georhan

       
      • Nobody/Anonymous

        Hi Georhan......

        i comment #include, cause i though i don't need it...

        now i'd change the first lines like this:

        include <stdio.h>

        include <io.h>

        include <stdio.h>

        int main(void)
        {//clrscr();
        textcolor(3);
        cprintf("Test\r\n\r\n");

        .....but i get the same errors
        [Linker error] undefined reference to textcolor' [Linker error] undefined reference tocprintf'

        ....so what kinda #include do i need to put some color in my text ?

         
    • Nobody/Anonymous

      clrscr(); exists in C. It is defined in 'conio.h'. It works perfectly fine in Turbo C and Turbo C++, Borland C++. It doesn't work in Dev C++.I dont know why.

       
      • Nobody/Anonymous

        To reinforce what black_adder said ...

        clrscr() is not a standard C or C++ library function.

        conio.h is not a standard C or C++ header file.

        You need to know which libraries are standard and which are not. Many compilers have header files, functions, and libraries that are not standard. Ususally, the non-standard stuff is a small subset of the libraries shipped with a compiler.

        The gcc family of compilers is available on an extremely wide range of platforms for an extremely wide range of processors. It tries to be a portable as possible, so it tends to avoid including non-standard libraries.

        You can google for clrscr() replacements.

        A common one is

        system("clrscr");

        rr

         
        • Wayne Keen

          Wayne Keen - 2004-11-26

          I think you meant:

          system("CLS");

          There is not clrscr command, at least not on my system. Note it will compile with just about anything in the "system", I even put in

          system("waynesaputz");

          and it compiled (truth compiles you know), but you will get a run-time error. (A non-crashing run-time error - which is cool to me)

          Wayne

           
          • Nobody/Anonymous

            Your right.

            sigh. Careless errors in 2 posts in 2 days. sigh.

            rr

             
            • Wayne Keen

              Wayne Keen - 2004-11-26

              At this rate, you will catch up to my total errors in the year 5454!

              :)

              Wayne

               
    • Nobody/Anonymous

      If you do a

      include <conio.c>

      instead of <conio.h> then clrscr() will work.

      I think it is a problem with the linker. It either cant
      find the object code for clrscr() or it does not exist.

       
      • aditsu

        aditsu - 2004-11-28

        no, you should never #include a c or cpp file, they're not meant to be included!
        it is a really evil thing to do
        (ask if you want more details)

        instead, you should either include that file in the project, or link the corresponding object file or library if you have it (if you don't have it, you can make it)

        anyway, Dev-C++ 4.9.9.0 (with MinGW) doesn't come with a conio.c (and its conio.h lacks most conio functions), and if you get the conio package from my web site then you get a library that you can link, and clear instructions

        Adrian

         
    • Nobody/Anonymous

      textcolor() does not exist in Dev-cpp and for some reason, the cprintf() is declared as _cprintf() and I think the funtion is defined in <conio.h> but I am not sure.

       

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.