91 Replies - 48737 Views - Last Post: 31 December 2010 - 08:36 AM
#16
Re: Holding The Execution Window Open
Posted 21 October 2007 - 02:33 PM
first line hitting return ok
second hitting return it closes
and no2pencil no cin
same as read only?
is there no other way that wont close
even hitting return until you die?
#17
Re: Holding The Execution Window Open
Posted 17 December 2007 - 04:24 PM
as long as the buffer is clear anyway?
#18
Re: Holding The Execution Window Open
Posted 03 February 2008 - 12:14 AM
http://nehe.gamedev....n.asp?lesson=01
will be the source of the base of this code...
if you are not using <windows.h> just ignore this post
/* PSUEDO */
add a bool array of 256;
add a MSG;
send to registered WNDPROC
determine wether they key is acceptable or not for exiting or any
other command
and if so exit...
exa:CODE
/* global if you want */
bool keys[256];
/* WINMAIN - just for kicks */
bool exit;
MSG msg; // no further handling needed
/* where you want input without continuing */
while (!exit)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
// do whatever from send to WNDPROC to asserting the keys here
}
// if you send to WNDPROC(HWND,MSG,HWORD,LWORD) make sure that
// you test when finished ^note there is not bool* so thats why global
// to make sure that exit can be true by
if ( keys[VALUE_FOR_EXIT] ) exit=true;
}
This post has been edited by draike: 03 February 2008 - 12:18 AM
#19
Re: Holding The Execution Window Open
Posted 14 February 2008 - 08:15 AM
#20
Re: Holding The Execution Window Open
Posted 22 March 2008 - 04:28 AM
int main()
{
char garbage;
{
body
}
cin<<garbage;
return 0;
}
This post has been edited by Sepanto: 22 March 2008 - 04:29 AM
#21
Re: Holding The Execution Window Open
Posted 27 March 2008 - 06:55 PM
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
int stop;
cin >> stop;
return 0;
}
#22
Re: Holding The Execution Window Open
Posted 09 April 2008 - 04:09 AM
#include <stdio.h>
int main(void)
{
printf("Hit \"Enter\" to continue\n");
fflush(stdin); /* Remove anything that is currently in the standard input */
getchar(); /* Wait for the user to hit the enter key */
fflush(stdin); /* Remove any additional charcters the user may have inputed */
return 0;
}
Of course, this is a lot more useful as a macro
#include <stdio.h>
#define PAUSE {printf("Hit \"Enter\" to continue\n");fflush(stdin);getchar();fflush(stdin);}
int main(void)
{
PAUSE
return 0;
}
PAUSE contains it's own scope, so it will not produce adverse effects. IE, this will work
if(foo) PAUSE;
Now, I personally don't like to have to key a extra key to quit, but I love the macro for debugging, as long as you remove the printf(). For example, useing a non recursive string reversal.
#include <stdio.h> /* fflush(), getchar(), printf(), stdin */
#include <string.h> /* strlen() */
#define PAUSE {fflush(stdin);getchar();fflush(stdin);}
void ReverseString(char *str);
int main(int argc, char *argv[])
{
if(argc != 2)
{
printf("Usage: %s \"TEXT\"\n", argv[0]);
return 0;
}
ReverseString(argv[1]);
printf("%s\n", argv[1]);
return 0;
}
void ReverseString(char *str)
{
int len = strlen(str) - 1;
int i;
char c;
for(i = 0; i < len; ++i, --len)
{
c = str[i];
str[i] = str[len];
str[len] = c;
/* Note: These are offset to the left to make it apparent they are debug data */
{
int j;
printf("%s\n", str);
for(j = 0; j < i; ++j)
putchar(' ');
putchar('^');
for(; j < len - 1; ++j)
putchar(' ');
putchar('^');
PAUSE;
putchar('\n');
}
}
}
Edit: Forgot a fflush(stdin);
This post has been edited by Cerolobo: 09 April 2008 - 04:47 AM
#23
Re: Holding The Execution Window Open
Posted 19 April 2008 - 08:02 PM
Amadeus, on 19 Jul, 2007 - 09:50 AM, said:
Are developers who don't know simple things, like how to stop the debugger from closing the console window after execution has stopped, really interested in porting code to multiple platforms?
Better than any of these recommendations, in my opinion, is to learn how to use the debugger. If someone wants to view the output before the application closes, then they should place a breakpoint in the code before the application closes. Debugging is an important skill. You can't start too early!
#24
Re: Holding The Execution Window Open
Posted 23 April 2008 - 03:23 AM
xtreampb, on 4 Oct, 2007 - 08:08 AM, said:
if the name of my program was "Game_Over" i would type
Game_Over.exe pause
and i would just execute the batch file. but the only problem is that the name of the exe. file has to be one word.
Quoting a really old post here, but just thought I'd have a little input
The file doesn't have to be one word, you could do something like this:
"game over.exe" pause
#25
Re: Holding The Execution Window Open
Posted 24 April 2008 - 07:58 AM
mikeblas, on 19 Apr, 2008 - 11:02 PM, said:
Amadeus, on 19 Jul, 2007 - 09:50 AM, said:
Are developers who don't know simple things, like how to stop the debugger from closing the console window after execution has stopped, really interested in porting code to multiple platforms?
Better than any of these recommendations, in my opinion, is to learn how to use the debugger. If someone wants to view the output before the application closes, then they should place a breakpoint in the code before the application closes. Debugging is an important skill. You can't start too early!
An excellent point...but I fully expect that well over 95% of the users of this board not to use a debugger. Further, i usually try to endorse proper debugging through the use of old school debugging techniques - the manual insertion of specific breakpoints in the code.
If you review many of the topics on the board that ask about holding the execution window open, most are not trying to track bugs...they are only trying to see the end result, but have only ever learned how to program using an IDE and do not understand how that IDE works. Despite the fact that I have grave reservations about programmers who ONLY know how to use an IDE, I try to at least provide them with some basic understanding of that IDE's functionality.
Frankly, if I had the time to explain how to use the debugger (or debug mode) of whatever IDE/compiler they are using, I'd point them towards the documentation for that specific IDE/complier and use the time to have a beer.
#26
Re: Holding The Execution Window Open
Posted 10 July 2008 - 12:12 PM
#27
Re: Holding The Execution Window Open
Posted 06 August 2008 - 10:52 AM
Our tutors at university have always said to use
while(!_kbhit());in order to hold the screen for input. This is in the conio.h library & it works perfectly in Visual Studio 2005.
What I'd like to know is why hasn't this really been mentioned much & why doesn't it seem to be used commonly?
Also, what would be the best code to use, which does the same function as kbhit, which is cross-platform & cross-compiler?
Thanks in advance.
cJr.
This post has been edited by cJr.: 06 August 2008 - 11:25 AM
#28
Re: Holding The Execution Window Open
Posted 06 August 2008 - 11:02 AM
However, I would still advise against the use of it, since conio.h does not conform to all standards, and it isn't going to be around forever. I always see a lot of people using conio.h in their programs~ granted, it has some very useful functions, but it's best to stick to the standards.
Personally, I tend to use cin.get (); (in C++ anyway)
Granted, it waits for the user to press enter, but we could just prompt them:
#include <iostream>
void pause ()
{
std::cout << "\nPress the enter key to continue . . .";
std::cin.get ();
}
int main ()
{
pause();
return EXIT_SUCCESS;
}
#29
Re: Holding The Execution Window Open
Posted 06 August 2008 - 11:39 AM
You've cleared it up for me now, thank you.
I will try & use:
cin.get();in future & see how I get along
#30
Re: Holding The Execution Window Open
Posted 06 August 2008 - 11:43 AM
I personally don't think it's too good an idea, I'm just intrigued as to why a higher-level education would suggest using something like that.
|
|

New Topic/Question
Reply





MultiQuote









|