Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Learning C through K&R book

Name: Anonymous 2011-08-24 21:12

I already compiled and ran my first code but there's this thing.
When I run it, cmd flashes and disapears.(I'm using Dev-C++ on windows to make it)
Anyways, I think there was a command or function to make the cmd pause till I press enter or something like that so that I am able to read whatever the output was, the thing is, I cant remember the name of the function or how to write it.
Can one of you tell me which it is, if there is one.
BTW here's my code:


#include <stdio.h>

main ()
{
  printf("Hello World!");
}

Name: Anonymous 2011-08-25 22:14

>>39
The code posted in >>38 won't be any different than what you did.

Basically when you run a program, like you did, it will open up an instance of the command prompt (if you're on windows), run the code, and then when it's finished it will close that command prompt because there is no need for it to stay open when it's done.

You can get around this one of two ways. Using getchar() will wait for you to enter a character. You're not actually doing anything with that character, you're just exploiting the fact that the program is stalled and you can see what was output.

The second, and better, way to do it is to open your own instance of the command prompt. Navigate to the folder your program is in by entering "cd C:\path of your program\".
Then enter "program.exe" to run that program.

Don't bother hitting compile and run in the second case, just compile.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List