Welcome! Log In Create A New Profile

Advanced

Another Compiler problem

Posted by Anonymous User 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Anonymous User
Another Compiler problem
March 22, 2006 05:46PM
When I compile it all works fine, but when I try to run my programsthe output screen only flashes and goes away. I've done all the trouble shooting, including typing the "system ("pause"winking smiley;" statement just before the return statement, but still I get the same effect. Anybobdy with some bright ideas?
Re: Another Compiler problem
March 22, 2006 08:51PM
Go to TOOLS, Environment Options, and click on "Console window remains open". If the checkbox next to it is already ticked, click it again.
avatar Re: Another Compiler problem
March 23, 2006 12:39AM
Hi

You need to understand that so far, we've only created console programmes. What this means is that you are supposed to type in the programme name at a console (e.g. DOS command window), the programme will run and when finished, the control passes back to the command prompt.

The problem you're getting is not really an error but rather an annoyance. What happens is that when you run the programme, Windows recognises that it is a console programme so it opens a console window (The one with the black background and the white text). Then your programme starts executing the code in main() . If you've written your programme in the normal way, execution will eventually reach the return 0; statement. When this happens, your programme exits and control returns to Windows.

Since there is nothing more for the console to do, Windows closes it down. If your programme is very short (most likely all of them this year), the time between starting your programme and it finishing is so short that the window just flashes by, as you've noticed.

There are several ways to get around this, one of which is to use the pausing thing you mentioned. Another is to just have the programme wait for you to enter some arbitrary text:

char ch;
cin >> ch;

These are all just hacks though. Since the programme is meant to run under a console environment, the most obvious thing to do is actually run it in a console window. Opening up the command prompt usually starts you off in the Windows directory or your home directory. Just navigate to your directory where the executable is, using the change directory command (cd) and then type in the programme name. e.g. If I want to run the Hello World programme and all my programmes are in the C:\unisa\cos211 directory, the following will be in the console window.

---------------------------------
C:\WINDOWS>cd \unisa\cos211
c:\unisa\cos211>cd Hello
C:\unisa\cos211\Hello>helloworld
Hello World!

C:\unisa\cos211\Hello>_

----------------------------------

I know this looks like too much work to get a simple programme to run but what do you expect? We're writing simple console programmes. Don't expect them to be like ordinary GUI Windows programmes.
Cheers
Rob
Anonymous User
Re: Another Compiler problem
March 23, 2006 08:57AM
Another simple hack is to use the sleep function
e.g Sleep(5000)

this causes the console window to pause for the specified number of milliseconds.

Bini
Re: Another Compiler problem
March 24, 2006 08:30AM
Hi Guys

Another issue regarding the dev C++ compiler is storing your program files in folders where the name of the folder contains a space.For example storing your files in the My documents folder could cause the problem of the console window disappearing.

regards
Lazarus Aron
Sorry, only registered users may post in this forum.

Click here to login