Siimple c question

Started by
8 comments, last by Nice Coder 19 years, 1 month ago
Hi, could someone please tell me what function pauses a console program to stop it from dissapearing at the end. Is it readln() or something like that? Thanks :)
Advertisement
system("pause"); is one, but there are many other ways.
Hi Drew,
Thanks but i dont think that is c. I get a compiler error as it doesn't recognize system.
getc(stdin)
Quote:Original post by one mind
Hi Drew,
Thanks but i dont think that is c. I get a compiler error as it doesn't recognize system.


system() is a standard C function... Your OS may not have a pause command/program, though.

You need to #include <stdlib.h>
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
It's really bad form, anyway. Console programs are meant to be run from the console and should close when they're finished.
#include <conio.h>

getch() is a favorite of mine (dunno if its standard or not though)

hope that helps
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
Thanks guys
System(pause) works nicely

Quote:It's really bad form, anyway. Console programs are meant to be run from the console and should close when they're finished.


Programs are supposed to run the way you want them to :)
Quote:Original post by one mind
Programs are supposed to run the way you want them to :)


The proper way to do it is to create a batch file that runs your program and then calls pause.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Thanks :)

This topic is closed to new replies.

Advertisement