Thread: Compiling for Windows

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    2

    Compilin C for Windows

    Hello, I'm new to C Programming just finished lesson 2.
    I'm trying to compile my test program that contains stuffs i learned from lesson 1 and 2, i compiled using Code Blocks using GCC compiler, if i start the program using code blocks it runs correctly but if i run the application from its folder it doesn't, it exits after i press enter without going to the next actions.

    Can someone tell me how to compile it to run for Windows Vista using code blocks?Thanks in advance!



    Code:
    #include <stdio.h>
    
    int main()
    {
     printf ("Welcome\n");
     int age;
     printf ("Please enter your age before you can continue:");
     scanf ("%d", &age);
     if (age<18) {
         printf ("You are too young, Please enter to exit.\n");
         getchar();
         return 0;
         }
    
    printf ("You are %d yrs old, cool.\n", age);
    getchar();
    return 0;
    
    }
    Last edited by markaizer; 05-21-2010 at 09:08 AM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    When you run your program inside C::B, it doesn't run your program directly; it calls a batch file that runs your program and then waits for (more) input so that you can see the final result. If you double-clicked your program from the folder, it ran to completion and then stopped, which on the face of it seems like a reasonable thing to do. To run a console app, you need to pop open a DOS box and type the name of the program (once you get to the folder).

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2
    Thank you very much!

  4. #4
    Trying to Learn C nathanpc's Avatar
    Join Date
    Jul 2009
    Location
    Brazil
    Posts
    72
    I also suggest you to use an normal editor, like Notepad++, and use MinGW, that is the GCC for Windows and do all in command-line, what will be like you will do on Linux.
    Follow Me At Twitter
    Eee PC 904HD White | Windows XP Home Edition and Linux Ubuntu Hardy Herron

    Google Talk: [email protected]
    ICQ: 424738586
    AIM: nathanjava

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling errors and using Cmake Set Policy
    By eligor in forum Linux Programming
    Replies: 2
    Last Post: 01-25-2010, 01:43 PM
  2. Compiling Issues
    By pc_doctor in forum C Programming
    Replies: 3
    Last Post: 11-30-2007, 10:00 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Compiling
    By Dae in forum C++ Programming
    Replies: 7
    Last Post: 06-15-2005, 01:08 AM
  5. Compiling in Unix vs Visual C++
    By stimpyzu in forum C++ Programming
    Replies: 2
    Last Post: 09-30-2002, 06:41 AM