Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 19th, 2005, 11:51 PM   #1
davidguygc
Programmer
 
Join Date: Mar 2005
Location: Lubbock, TX
Posts: 30
Rep Power: 0 davidguygc is on a distinguished road
My C programs instantly close

I am just starting out on programming. I am using Microsoft Visual C++, and when i run the program in there, it will ask to press a key to close, but when i find the program on the computer, it closes the instant the program is done instead of waiting for you to close it yourself. Is there a better C compiler and development program out there that's free?
Thanks,
David
davidguygc is offline   Reply With Quote
Old Mar 19th, 2005, 11:54 PM   #2
davidguygc
Programmer
 
Join Date: Mar 2005
Location: Lubbock, TX
Posts: 30
Rep Power: 0 davidguygc is on a distinguished road
P.S. - I put
getchar();
at the end of my programs and it still does it
davidguygc is offline   Reply With Quote
Old Mar 19th, 2005, 11:56 PM   #3
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 550
Rep Power: 4 Benoit is on a distinguished road
Programs close when they get to the end of the code

You could use getchar() at the end, or include stdlib.h and use
system("pause");
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4
Benoit is offline   Reply With Quote
Old Mar 20th, 2005, 12:55 AM   #4
HelloWorld
Newbie
 
Join Date: Mar 2005
Posts: 4
Rep Power: 0 HelloWorld is on a distinguished road
cin.ignore();
cin.get();
HelloWorld is offline   Reply With Quote
Old Mar 20th, 2005, 12:58 AM   #5
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Post the code here.

Also, the getche() function in conio.h might solve your problems instead of getchar().
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Mar 20th, 2005, 5:11 AM   #6
Mad_guy
Hobbyist Programmer
 
Mad_guy's Avatar
 
Join Date: Oct 2004
Location: Sandstorm, Techno Club
Posts: 239
Rep Power: 4 Mad_guy is on a distinguished road
Send a message via AIM to Mad_guy Send a message via MSN to Mad_guy
Quote:
Originally Posted by Benoit
Programs close when they get to the end of the code

You could use getchar() at the end, or include stdlib.h and use
system("pause");
No. Never use system(); calls in a program that doesn't require them.

It's truthfully frusterating when people make system(); calls in a program that isn't Windows centric, like programs that involve Win32 and/or WinSock programming. Or something of the like, such as Registery editing.


You should use Getchar(); or getch(); at the end of your code. But getch(); isn't part of the ANSI C standard so it might not work.

The only reason I can think this is happening, is that you fucked up somewhere in your code in which case stuff is truncated. It's happened to me, with scanf(); and truncating spaces.

Last edited by Mad_guy; Mar 20th, 2005 at 5:13 AM.
Mad_guy is offline   Reply With Quote
Old Mar 20th, 2005, 5:08 PM   #7
davidguygc
Programmer
 
Join Date: Mar 2005
Location: Lubbock, TX
Posts: 30
Rep Power: 0 davidguygc is on a distinguished road
is there a different development program i can use instead of microsoft visual c++?
davidguygc is offline   Reply With Quote
Old Mar 20th, 2005, 5:10 PM   #8
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
There's Dev-C++.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Mar 20th, 2005, 5:20 PM   #9
davidguygc
Programmer
 
Join Date: Mar 2005
Location: Lubbock, TX
Posts: 30
Rep Power: 0 davidguygc is on a distinguished road
where do i get it?
davidguygc is offline   Reply With Quote
Old Mar 20th, 2005, 7:02 PM   #10
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 707
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
there is also gcc, many windows ports of it also.
thechristelegacy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:57 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC