![](smile.gif)
Please help me - I'm befuddled!
Hello,
I am trying to teach myself C programming from several books, and I am having trouble getting any compiler to work on my computer. When I compile then execute, the DOS console just pops up for a split second then disappears again. The compile had no errors, the window just won''t stay up. I am using Bloodshed DevC++ (or trying to!)
I found an FAQ on this exact problem and it told me to go into the project settings and deselect "do not create council." I did this, and nothing changed. Then I went through the program and literally tried every combination of setting, to no avail. I thought that maybe the compiler was messed up, so I uninstalled it then reinstalled in, then uninstalled it and tried DJGPP, turbo C, and Miracle C in sucession, all of which had the exact same problem. So I decided that the problem must be some setting in my system, and I started to search through online tutorials and FAQs. I found one that addressed this problem, which told me to go into the MS-DOS command.pif file under windows, open its properties, then deselect the option "close on exit." I tried this, and it didn''t fix the problem. I just spent the evening going through every type of system setting I could find on that stupid computer, and I can''t find anything that could fix this problem. I asked some of my level editing friends who know some programing, but none of them could help me. Please please help me! I know it is probably just some stupid option I need to check or uncheck, but I really can''t figure it out. I have Windows Me. I really appreciate any responses.
![](smile.gif)
Thanks for the suggestion, but I already tried it! Unfortunately you can''t restart Windows ME in MS-DOS mode, but I did open the DOS window and tried to run it from there. As soon as I tried to execute any program I had compiled, the window closed after a split second. Do you have any other suggestions? Or is there some special way I need to start it from the DOS prompt?
What kind of program are you trying? Does it accept input?
Enter learning mode for a second.
Okay, a MS-DOS app quits when it is done doing its job. If you are just multiplying and printing a result, the app will exit right after. You have to halt the program for a second to show the answer, or get an input. Have you learned getch() yet?
If you answered yes to some of those questions, I have no idea what''s wrong.
Enter learning mode for a second.
Okay, a MS-DOS app quits when it is done doing its job. If you are just multiplying and printing a result, the app will exit right after. You have to halt the program for a second to show the answer, or get an input. Have you learned getch() yet?
If you answered yes to some of those questions, I have no idea what''s wrong.
C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!
What kind of program are you trying? Does it accept input?
Enter learning mode for a second.
Okay, a MS-DOS app quits when it is done doing its job. If you are just multiplying and printing a result, the app will exit right after. You have to halt the program for a second to show the answer, or get an input. Have you learned getch() yet?
If you answered yes to some of those questions, I have no idea what''s wrong.
I am Nobody, who are you? Are you Nobody too?
Enter learning mode for a second.
Okay, a MS-DOS app quits when it is done doing its job. If you are just multiplying and printing a result, the app will exit right after. You have to halt the program for a second to show the answer, or get an input. Have you learned getch() yet?
If you answered yes to some of those questions, I have no idea what''s wrong.
I am Nobody, who are you? Are you Nobody too?
C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!
I''m just beginning, and you lost me already, which probably means you can help me fix my problem. Can you please explain in more depth? Or do you know of any place I can find a detailed explanation of this? I really appreciate your help. It''s hard to get started with something totally new with no one around to point things out.
![](smile.gif)
When a DOS based program is done doing whatever you tell it to do it exits. So if it prints something on the screen you can''t see it because it closes to fast. by putting a call to the function Getch(); which is (I believe) in the header file. This waits until a user presses a key to return so dos will have to wait until a key is pressed to exit. I would assume having unchecked the "close on exit" box would have helped but adding getch(); might help. btw, put it at the very end of the prog, or wherever you want a pause.(before the end main bracket usually)
Use the WriteCoolGame() function
Works every time
Use the WriteCoolGame() function
Works every time
Use the WriteCoolGame() functionWorks every time
It''s been awhile since I last programmed under DOS ...
Look for documentation on: getc(), getch(), getchar() ...
(some are functions, some are macros, some default to
stdin for input, others require a ''stream'' for I/O ...)
Insert something like:
keystroke = getchar();
near the end of your program.
It is possible that your program is working just fine, and just a little too quickly for you to read it''s output before the OS shuts down your output window. Asking the user for input of any kind just before program termination should keep your window open ''till the user is finished.
Good Luck.
Look for documentation on: getc(), getch(), getchar() ...
(some are functions, some are macros, some default to
stdin for input, others require a ''stream'' for I/O ...)
Insert something like:
keystroke = getchar();
near the end of your program.
It is possible that your program is working just fine, and just a little too quickly for you to read it''s output before the OS shuts down your output window. Asking the user for input of any kind just before program termination should keep your window open ''till the user is finished.
Good Luck.
Thank you guys so much! I think that getchar() is just what I needed to do the trick! Its funny that these books don''t talk about it until around page 200, but expect you to be able to see the results in an open window after you execute from page 1. I just added getchar() to the end of my project and the window stayed nice and open.
I really really appreciate it - I was at my wits end.
![](smile.gif)
![](smile.gif)
quote:
Original post by rainbird
Thank you guys so much! I think that getchar() is just what I needed to do the trick! Its funny that these books don''t talk about it until around page 200, but expect you to be able to see the results in an open window after you execute from page 1. I just added getchar() to the end of my project and the window stayed nice and open.I really really appreciate it - I was at my wits end.
![]()
It''s not that they expect an open window, they actually expect NO window. These are DOS programs, written for DOS compilers. Not Windows console apps. If you for instance had a book on Visual C++ and it started you out learning Console Apps, this would''ve been covered(or some variant thereof)to keep the window open long enough to see it.
Be
![](smile.gif)
It''s Da BOMB Baby!!!
. o O ~
A little nonsense now and then,
is relished by the wisest men
~ O o .
-- Willy Wonka
BeSIt's Da BOMB Baby!!!. o O ~ A little nonsense now and then,is relished by the wisest men~ O o .-- Willy Wonka
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement