Thread: How to setup visual c++ 6.0 to compile and run a C program?

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    9

    How to setup visual c++ 6.0 to compile and run a C program?

    I'm trying to build and run a C program in Visual C++ 6.0 but, even if my code is correct (I copy-pasted it from a reliable source), I still get errors. I remember that my teacher instructed us to configure the IDE such that it compiles a C program but I don't remember how it was done. Please help! Really urgent!
    Last edited by BrandNewDeipz; 06-20-2012 at 06:30 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > even if my code is correct (I copy-pasted it from a reliable source), I still get errors
    As a newbie, how would you determine what a "reliable source" is?
    And post your actual error messages.

    > I remember that my teacher instructed us to configure the IDE such that it compiles a C program
    Well making sure you name all the source files as prog.c (and NOT prog.cpp) is one way.
    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.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    9
    Code:
    #include<stdio.h>
    #include<conio.h> 
    main()
    {   
       textcolor(RED);   
       cprintf("C programming");    
       getch();   
       return 0;
    }
    warning C4013: 'textcolor' undefined; assuming extern returning int
    error C2065: 'RED' : undeclared identifier

    I already changed .cpp to .c but I still get the same error.

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Heh, reliably obsolete is what that load of rubbish is.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    <conio.h> is not a standard header. Functions and constants within it (textcolor(), RED, cprintf(), and getch()) are also non-standard, and not supported by most compilers.

    You also need to specify explicitly that main() returns int (i.e. "int main() ...."). That is deprecated in C, and usually considered bad practice. When compiling as C++ (e.g. with a .cpp extension) it will give another compilation error.

    This means that most of the lines you have obtained from your "reliable source" are invalid. Visual C++ 6.0 is not exactly the most modern compiler, but the error messages it is giving for that code are completely appropriate.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  6. #6
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Lol, you have three function calls, none of which are supported by standard C.

    - Get rid of textcolor (use ncurses if you really want that functionality).
    - Change cprintf to just regular printf.
    - Change getch to getchar.

  7. #7
    Registered User
    Join Date
    Mar 2012
    Posts
    9
    Oh. I see. I said it was reliable because it was recommended by our teacher. Thank you for the tips and info.

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Perhaps you should have started with the most basic "hello world" style program to test your compiler:

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        printf("I like cats.");
        return 0;
    }
    The best part - if you understand Chapter 1 of any 'C' book, you could write this yourself and bypass the copy + paste method for such a simple test.

  9. #9
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    those are TurboC (ancient obsolete compiler) specific functions. s this where you got the code? textcolor in c
    if your instructor said to get it from there, i don't know what to say.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about program setup
    By vnet_hacker in forum C Programming
    Replies: 3
    Last Post: 03-01-2012, 07:16 PM
  2. Visual Studio Setup
    By Tonto in forum Tech Board
    Replies: 4
    Last Post: 12-13-2008, 05:29 PM
  3. start the program when GUI is setup on Linux
    By manav in forum Linux Programming
    Replies: 2
    Last Post: 03-26-2008, 04:02 AM
  4. Cannot compile a C program in Visual C++ Express
    By daYz in forum C Programming
    Replies: 10
    Last Post: 03-09-2008, 10:47 AM
  5. Socket Program includes and setup
    By Ianel in forum Networking/Device Communication
    Replies: 2
    Last Post: 09-23-2003, 05:23 PM