[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


C & .NET

Posted on 2007-07-20
Medium Priority
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
  • 3
LVL 13

Assisted Solution

josgood earned 375 total points
ID: 19534781
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.

Author Comment

ID: 19535246
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

josgood earned 375 total points
ID: 19535292
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

ID: 19537383
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.

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

873 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