C & .NET

Posted on 2007-07-20
Last Modified: 2013-11-26
I want to use my Visual Studio .NET (2003) to run simple ANSI C programs.  I can get them to run if I use the "Start without Debugging".  If I use the regular "Start" button, it runs, then immediately closes the console window.  Also, when I run the executable from the file folder, it opens & closes, the same way.  Is there some option(s) that can let me just run the program using "Start"
Question by:walang
    LVL 13

    Assisted Solution

    It sounds like this is a console program and the program is running to completion and then closing.  

    You can have the program stop, when finished, and wait for input.

    #include <conio.h>

    as the last line before your closing brace.
    LVL 1

    Author Comment

    Looks like it does work, if I put the  _getch();  right before the  return 0;
    What is it that this is doing?  Are there any other suggestions, besides code?
    LVL 13

    Accepted Solution

    If you are restricting yourself to ANSI -- and don't want to use a vendor-defined header -- you can use

    #include <stdio.h>

    for example,

    #include <stdio.h>

    void main() {
       char c = getchar();

    This requires you to enter a non-space character followed by Enter.

    The other _getch() solution requires a single charatcer input.
    LVL 13

    Expert Comment

    Sorry, I didn't see your post before sending my last one.

    _getch() waits for a keystroke.  If that doesn't prevent the program from exiting then either your code exits before then or you have a stream of stdin data that satisfies the _getch().

    Another suggestion: Open a console window and run the program from the console.  Here are instructions -- please forgive me if you already know all this.

    1)  Click the Start button.
    2)  Click Run
    3)  In the text area of the popup window, enter CMD and then press the Enter key
    4)  Change directory to the folder containing your executable.  For example, if your program is in
         C:\MyProgram\Debug, then enter
         cd C:\MyProgram\Debug
    5)  Type the name of your program, e.g. MyProgram.exe
        and then press the enter key.

    Hope this helpls.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now