Holding The Execution Window Open

Title 2: How do I pause for input?

  • (7 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »

91 Replies - 61591 Views - Last Post: 31 December 2010 - 08:36 AM Rate Topic: -----

#31 CalumJR  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 10-May 08

Re: Holding The Execution Window Open

Posted 06 August 2008 - 12:33 PM

Thank you for the idea. I will ask them, especially when now I've just changed all the code in this big program I am making to "cin.get();" instead of "while(!_kbhit());" and it works perfectly! :) lol.
Was This Post Helpful? 0
  • +
  • -

#32 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,142
  • Joined: 14-September 07

Re: Holding The Execution Window Open

Posted 07 August 2008 - 07:52 AM

Weird, I have never seen kbhit either...
Was This Post Helpful? 0
  • +
  • -

#33 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Holding The Execution Window Open

Posted 18 August 2008 - 02:32 PM

@cJr:
Did you ask your teachers why they suggested that?
Was This Post Helpful? 0
  • +
  • -

#34 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,142
  • Joined: 14-September 07

Re: Holding The Execution Window Open

Posted 27 August 2008 - 06:29 PM

:lol:
Was This Post Helpful? 0
  • +
  • -

#35 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Holding The Execution Window Open

Posted 28 August 2008 - 03:33 AM

That was his first post.

Was that supposed to offend us?
Was This Post Helpful? 0
  • +
  • -

#36 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,142
  • Joined: 14-September 07

Re: Holding The Execution Window Open

Posted 28 August 2008 - 07:55 AM

I guess...?
Was This Post Helpful? 0
  • +
  • -

#37 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Holding The Execution Window Open

Posted 28 August 2008 - 08:13 AM

Hey, android 16, was you aiming to insult us?
Was This Post Helpful? 0
  • +
  • -

#38 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,142
  • Joined: 14-September 07

Re: Holding The Execution Window Open

Posted 28 August 2008 - 08:19 AM

We don't take kindly to fellows....


I'm looking for the guy who shot my Pa.
Was This Post Helpful? 0
  • +
  • -

#39 CalumJR  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 10-May 08

Re: Holding The Execution Window Open

Posted 28 August 2008 - 12:36 PM

View Postgabehabe, on 18 Aug, 2008 - 10:32 PM, said:

@cJr:
Did you ask your teachers why they suggested that?



No, I haven't been able to yet as I haven't been back to uni. I start again in late September. But I will try & email one of them if f I can.
Was This Post Helpful? 0
  • +
  • -

#40 RedSonja  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 172
  • Joined: 04-September 08

Re: Holding The Execution Window Open

Posted 04 September 2008 - 01:55 AM

Cheap and nasty way I use every day to start exe files and see what they are doing (I do a lot of old code).


Make a little text file, call it run.bat. Put this in it:

MyStuff.exe
pause



double click it, a DOS window opens, your exe writes its stuff in there and won't go away till you tell it to.
Was This Post Helpful? 0
  • +
  • -

#41 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Holding The Execution Window Open

Posted 04 September 2008 - 02:48 AM

Seems a little pointless, and it will only run on Windows.

All that you're achieving by putting "pause" at the end of that batch file is the equivalent to this:
system ("pause");
Was This Post Helpful? 0
  • +
  • -

#42 RedSonja  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 172
  • Joined: 04-September 08

Re: Holding The Execution Window Open

Posted 04 September 2008 - 03:25 AM

View Postgabehabe, on 4 Sep, 2008 - 02:48 AM, said:

Seems a little pointless, and it will only run on Windows.

All that you're achieving by putting "pause" at the end of that batch file is the equivalent to this:
system ("pause");



Yes, you are right. A great deal of what I do seems pointless. Unfortunately I am obliged to work under Windows at the moment. (Some day the customer will want Vista, oh my.) Me, I dream in Unix. I do so miss vi.

Anyway, the point is, my batch file method works without changing the code. Sometimes I only have the exe and no source code.
Was This Post Helpful? 0
  • +
  • -

#43 krzysz00  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 83
  • Joined: 25-February 09

Re: Holding The Execution Window Open

Posted 02 March 2009 - 04:13 PM

getch(); is in the UNIX header ncurses.h . Link with -lncurses
Was This Post Helpful? 0
  • +
  • -

#44 webmin  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 21-May 08

Re: Holding The Execution Window Open

Posted 17 March 2009 - 04:00 PM

I think I've created a platform independent method of using system commands like "cls", "clear", or "pause", but I really need someone with a linux machine to test this on. Of course credit goes to some of the solutions I've seen on here, and one of my classmates who helped me specifically with automating the "cls" or "clear" process. Here's the code seeing as I can't upload header files:

#include <stdlib.h> //For system commands

//Detect and define which command to use
#ifndef WIN32
	#define COMMAND "clear" //Clears a linux console screen
#else
	#define COMMAND "cls" //Clears a windows console screen
#endif

#define wipe() system( COMMAND )
//To clear the console screen use wipe();

#define wait() {printf("Hit \"Enter\" to continue\n");fflush(stdin);getchar();fflush(stdin);}
//To pause the program or hold the console screen open use wait();



The commands should be pretty well commented, but just in case use:

wipe(); //This will clear the console screen
wait(); //This will pause the program waiting for input i.e a enter key pressed

I will even make this as easy as I can for you. Here's a program you can test this with:

#include <stdio.h>
#include <stdlib.h> //For system commands

//Detect and define which command to use
#ifndef WIN32
	#define COMMAND "clear" //Clears a linux console screen
#else
	#define COMMAND "cls" //Clears a windows console screen
#endif

#define wipe() system( COMMAND )
//To clear the console screen use wipe();

#define wait() {printf("Hit \"Enter\" to continue\n");fflush(stdin);getchar();fflush(stdin);}
//To pause the program or hold the console screen open use wait();

int main (void)
{
    printf("This is the console screen before we clear it.\n");
    wait();
    wipe();
    printf("A new line in the console screen. Looks like we cleared the screen successfully");
    wait();
}



Check that on your system for me and let me know how it works. Thanks.

This post has been edited by webmin: 17 March 2009 - 09:25 PM

Was This Post Helpful? 0
  • +
  • -

#45 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Holding The Execution Window Open

Posted 18 March 2009 - 05:48 AM

But you're using system() :(

View Postgabehabe, on 10 Jul, 2008 - 06:12 PM, said:

So many people use system("pause"); in Windows console apps...

DON'T!

here's why...


Also, as an aside: you've covered win and linux but what's the Mac command to do those things?

But still... system() :(

This post has been edited by gabehabe: 18 March 2009 - 05:49 AM

Was This Post Helpful? 0
  • +
  • -

  • (7 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »