none
compiler problem RRS feed

  • Question

  • Ok my problem is that I want to learn C before jumping into C++ or C# and was told to save the file as whatever.c. Well that works but i have no idea how to compile it using visual studio and it wont allow me to debug either. When i do it like this there is no Build button at the top. I go to new and click text file under general and save it as .c. Is there a button like F4 or F5 or something to press to build it? Part of my exercise is to run this program to see what it does then do some others and figure out the problems with the code. Thanks.


    -Thorium



    Saturday, March 24, 2007 10:14 PM

Answers

  • You need to create a solution before the IDE will build the code. You can do this through File->New Project. Make sure you chose Visual C++ Win32 Console Application and then add your code file to the resulting project. This can be done through right clicking on solution explorer then going to Add->Existing File and then point the dialog box to your code file.

    Of course, if you are writing a GUI app then you should choose Visual C++ Win32 Project. But since you said you were learning I assumed you wanted the console.

    Saturday, March 24, 2007 10:50 PM
  • There should be an option in the debug menu Start Without Debugging, or ctrl+f5 if you want short cut keys. That will stop it from closing right away.
    To stop it from wanting the pre-compiled headers, that's stdafx.h deselect it when you are creating a project. Oh, as a warning though if you do use it, its a good idea to put it first before any other includes.
    Sunday, March 25, 2007 9:56 AM

All replies

  • You need to create a solution before the IDE will build the code. You can do this through File->New Project. Make sure you chose Visual C++ Win32 Console Application and then add your code file to the resulting project. This can be done through right clicking on solution explorer then going to Add->Existing File and then point the dialog box to your code file.

    Of course, if you are writing a GUI app then you should choose Visual C++ Win32 Project. But since you said you were learning I assumed you wanted the console.

    Saturday, March 24, 2007 10:50 PM
  • ok that worked but i ran into another problem. It closes out and ive skimmed over this *small* program about 5 or 6 times to make sure i had it exactly s the book has it. My exercise it to know what the code does by running it but it closes out right away. Here is thee code

    #include <stdio.h>
    #include <stdafx.h>

    int x,y;

    main()
    {
        for ( x = 0; x < 10; x++, printf( "\n" ) )
            for ( y = 0; y < 10; y++ )
                printf( "X" );

        return 0;
    }

    #include <stdafx.h was pre-made when i did the project and had to add that into my code and that fixed my first error. Wasnt sure if i even need it for this program but it builds and all now just closes out. Ill mark as answerd tho since you helped with my main problem. Thanks

    -Thorium
    Sunday, March 25, 2007 5:01 AM
  • There should be an option in the debug menu Start Without Debugging, or ctrl+f5 if you want short cut keys. That will stop it from closing right away.
    To stop it from wanting the pre-compiled headers, that's stdafx.h deselect it when you are creating a project. Oh, as a warning though if you do use it, its a good idea to put it first before any other includes.
    Sunday, March 25, 2007 9:56 AM
  • ok thanks for the help
    Sunday, March 25, 2007 10:28 PM
  • The reason it's simply quitting out is that there's nothing keeping the app open. The return 0 on main() will exit the program, destroying the console window. You may notice that before it closes there may be some text displaying. See your book for console input to have the user type something in, like Enter, to have the program quit.
    Monday, March 26, 2007 7:55 PM
  • Your problem is that tools desinged to make things easier for experienced users actually have the reverse effect with newbies. stdafx.h is an include used by the precompiled header system to make programs compile faster. For a "Hello World" program, and even a reasonably large C program on a modern computer, the program will compile in under a second and it does more harm than good. So you've got to start a new project with precompiled headers unselected. Then you can add normal C files to the project, and compile the solution.
    Monday, March 26, 2007 8:58 PM
  • You won't believe how much I hate to see new users being tripped up by the very tools they are using to learn C++ New users shouldn't need to know about pre-compiled headers let alone understand them!
    Tuesday, March 27, 2007 4:24 AM
    Moderator