By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

How to prevent the quick disappearance of window

P: n/a
I am just beginning to learn C program and I am using Bloodshed Dev-C++
5 (currently beta) on Window XP. When I was running a very simple
program:

#include
<stdio.h>

int main()
{
printf( "I am alive! Beware.\n" );
return 0;
}

the window displaying this message just disappear before I have any
time to see my output, the same happens for other program. Can anyone
tell me how to fix this problem?

Jun 14 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a

kc************@yahoo.com.hk wrote:
I am just beginning to learn C program and I am using Bloodshed Dev-C++
5 (currently beta) on Window XP. When I was running a very simple
program:

#include
<stdio.h>

int main()
{
printf( "I am alive! Beware.\n" );
return 0;
}

the window displaying this message just disappear before I have any
time to see my output, the same happens for other program. Can anyone
tell me how to fix this problem?


If you ask in a Windows specific newsgroup I'm sure that many people
will
be able to give you an answer. Or read the documentation for this
Bloodshed
thing. Unfortunately all that is out of topic here.

Jun 14 '06 #2

P: n/a
kc************@yahoo.com.hk wrote:
I am just beginning to learn C program and I am using Bloodshed Dev-C++
5 (currently beta) on Window XP. When I was running a very simple
program:

#include
<stdio.h>
This is not a valid preprocessor statement.
int main()
{
printf( "I am alive! Beware.\n" );
return 0;
}

the window displaying this message just disappear before I have any
time to see my output, the same happens for other program. Can anyone
tell me how to fix this problem?


Yes. Add a getchar() just before the return from main(). Or run it
directly from the command prompt, or use some Windows-specific function
to pause the program, but the getchar() call is both simple and ISO C.

Richard
Jun 14 '06 #3

P: n/a
Richard Bos <rl*@hoekstra-uitgeverij.nl> wrote:
kc************@yahoo.com.hk wrote:
the window displaying this message just disappear before I have any
time to see my output, the same happens for other program. Can anyone
tell me how to fix this problem?
Yes. Add a getchar() just before the return from main(). Or run it
directly from the command prompt, or use some Windows-specific function
to pause the program, but the getchar() call is both simple and ISO C.


OT: one such appropriate windows-specific function is system("pause").

or you could just do
puts("");
puts("Press enter to continue...");
getchar();
return 0;
Richard

Jun 14 '06 #4

P: n/a
Jordan Abel wrote:
Richard Bos <rl*@hoekstra-uitgeverij.nl> wrote:
kc************@yahoo.com.hk wrote:
the window displaying this message just disappear before I have any
time to see my output, the same happens for other program. Can anyone
tell me how to fix this problem?


Yes. Add a getchar() just before the return from main(). Or run it
directly from the command prompt, or use some Windows-specific function
to pause the program, but the getchar() call is both simple and ISO C.


OT: one such appropriate windows-specific function is system("pause").

or you could just do
puts("");
puts("Press enter to continue...");
getchar();
return 0;


It's worth noting that simply calling getchar() will leave all
characters except the first one on the input stream if the user entered
any before pressing the "return" key which may not be desirable. In
such a case something like "while(getchar() != '\n')" may be preferred.

Robert Gamble

Jun 28 '06 #5

P: n/a
av
On 27 Jun 2006 22:59:51 -0700, "Robert Gamble" <rg*******@gmail.com>
wrote:
Jordan Abel wrote:
Richard Bos <rl*@hoekstra-uitgeverij.nl> wrote:
> kc************@yahoo.com.hk wrote:
>> the window displaying this message just disappear before I have any
>> time to see my output, the same happens for other program. Can anyone
>> tell me how to fix this problem?
>
> Yes. Add a getchar() just before the return from main(). Or run it
> directly from the command prompt, or use some Windows-specific function
> to pause the program, but the getchar() call is both simple and ISO C.


OT: one such appropriate windows-specific function is system("pause").

or you could just do
puts("");
puts("Press enter to continue...");
getchar();
return 0;


It's worth noting that simply calling getchar() will leave all
characters except the first one on the input stream if the user entered
any before pressing the "return" key which may not be desirable. In
such a case something like "while(getchar() != '\n')" may be preferred.

Robert Gamble


int c;

while( (c=getchar())!= '\n' && c!=EOF);

Jun 28 '06 #6

P: n/a
"Robert Gamble" <rg*******@gmail.com> writes:
Jordan Abel wrote:
Richard Bos <rl*@hoekstra-uitgeverij.nl> wrote:
> kc************@yahoo.com.hk wrote:
>> the window displaying this message just disappear before I have any
>> time to see my output, the same happens for other program. Can anyone
>> tell me how to fix this problem?
>
> Yes. Add a getchar() just before the return from main(). Or run it
> directly from the command prompt, or use some Windows-specific function
> to pause the program, but the getchar() call is both simple and ISO C.


OT: one such appropriate windows-specific function is system("pause").

or you could just do
puts("");
puts("Press enter to continue...");
getchar();
return 0;


It's worth noting that simply calling getchar() will leave all
characters except the first one on the input stream if the user entered
any before pressing the "return" key which may not be desirable. In
such a case something like "while(getchar() != '\n')" may be preferred.


This won't matter if it's the last thing you do before terminating the
program, but it's (almost) always a good idea to write code that could
be incorporated into something bigger later on.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jun 28 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.