[Solved] Pause Function

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: Pause Function

Post by M_D_K »

stupid retard wrote:noooooooobb

noob noob noob noob!

all you have to do is replace cin.get, with get(). NOOB!

that way, once any character is inputted, the program continues on. NEEEEWWWWBBB!!
get() wouldn't works since no standard function is called that. fucking retard.
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
voidcyrax

Re: Pause Function

Post by voidcyrax »

o
Last edited by voidcyrax on Tue Jun 30, 2009 8:02 pm, edited 1 time in total.
voidcyrax

Re: Pause Function

Post by voidcyrax »

ok, so I made one mistake. it is getchar(). so fucking what? do i still have to write it for you too?

listen, i understand you are a really bad newb, so let me try to help you here:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
...
getchar()
...
}

NEWB!!!
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: Pause Function

Post by M_D_K »

still won't compile since it's incorrect code.

n00b.
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
voidcyrax

Re: Pause Function

Post by voidcyrax »

mdk is nothing but fail. has to protect other users, and has to butt in things that don't concern him. the code is correct. the only thing missing is the semicolon, which im not going to fix for scriptkiddy zodiac, he can do it himself.
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: Pause Function

Post by zodiac976 »

voidcyrax wrote:ok, so I made one mistake. it is getchar(). so fucking what? do i still have to write it for you too?

listen, i understand you are a really bad newb, so let me try to help you here:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
...
getchar()
...
}

NEWB!!!
That doesn't work it only responds to 'ENTER'
and if you use getchar() like that it causes
more problems than cin.get().

I think you are using C includes...
these are for c++
#include <cstdio>
#include <cstdlib>

EDIT: you so funny :D.
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: Pause Function

Post by zodiac976 »

Actually I think I found something that is working better
than cin.get();.

void pause()
{
cout << "Press ENTER to continue . . .";
cin.ignore(9999, '\n');
}

No more bugs but still you have to hit 'ENTER'.
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Pause Function

Post by avansc »

zodiac976 wrote:Actually I think I found something that is working better
than cin.get();.

void pause()
{
cout << "Press ENTER to continue . . .";
cin.ignore(9999, '\n');
}

No more bugs but still you have to hit 'ENTER'.

yeah thats a brilliant way of doing it.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: Pause Function

Post by zodiac976 »

I found another way and tested it in my text RPG and
so far it works without relying on the 'ENTER' key but
I don't think it is a C++ standard.

You need #include <conio.h> to get it to work.
I thought conio was for some other compiler...
EDIT: I use visual C++ 2008 Express Edition.

void pause()
{
cout << "Press any key to continue . . .";
_getch();
}

I tried using just getch() and the compiler said to use
_getch(). So far I haven't gotten any errors with it.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Pause Function

Post by eatcomics »

voidcyrax wrote:You all suck
You're dumb go away
01001110
00110000
00110000
00111000
!!!!!!!!!!!!
Image
User avatar
dejai
Chaos Rift Junior
Chaos Rift Junior
Posts: 207
Joined: Fri Apr 11, 2008 8:44 pm

Re: Pause Function

Post by dejai »

system("PAUSE"); in general is a bad idea. If you had googled it you would have found this article:
http://www.gidnetwork.com/b-61.html

Let me quote it:
*

t's a very expensive and resource heavy function call. It's like using a bulldozer to open your front door. It works, but the key is cleaner, easier, cheaper. What system() does is:
1.

suspend your program
2.

call the operating system
3.

open an operating system shell (relaunches the O/S in a sub-process)
4.

the O/S must now find the PAUSE command
5.

allocate the memory to execute the command
6.

execute the command and wait for a keystroke
7.

deallocate the memory
8.

exit the OS
9.

resume your program

There are much cleaner ways included in the language itself that make all this unnessesary.
*
You must include a header you probably don't need: stdlib.h or cstdlib

It's a bad habit you'll have to break eventually anyway.

Instead, use the functions that are defined natively in C/C++ already. So what is it you're trying to do? Wait for a key to be pressed? Fine -- that's called input. So in C, use getchar() instead. In C++, how about cin.get()? All you have to do is press RETURN and your program continues.
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: Pause Function

Post by zodiac976 »

dejai wrote:system("PAUSE"); in general is a bad idea. If you had googled it you would have found this article:
http://www.gidnetwork.com/b-61.html

Let me quote it:
*

t's a very expensive and resource heavy function call. It's like using a bulldozer to open your front door. It works, but the key is cleaner, easier, cheaper. What system() does is:
1.

suspend your program
2.

call the operating system
3.

open an operating system shell (relaunches the O/S in a sub-process)
4.

the O/S must now find the PAUSE command
5.

allocate the memory to execute the command
6.

execute the command and wait for a keystroke
7.

deallocate the memory
8.

exit the OS
9.

resume your program

There are much cleaner ways included in the language itself that make all this unnessesary.
*
You must include a header you probably don't need: stdlib.h or cstdlib

It's a bad habit you'll have to break eventually anyway.

Instead, use the functions that are defined natively in C/C++ already. So what is it you're trying to do? Wait for a key to be pressed? Fine -- that's called input. So in C, use getchar() instead. In C++, how about cin.get()? All you have to do is press RETURN and your program continues.
I knew and know that :/.

I found that in google a long time ago and in my
previous posts I said it was bad and I wanted
to move away from it....if you are replying to me
that is... :|.
User avatar
Netwatcher
Chaos Rift Junior
Chaos Rift Junior
Posts: 378
Joined: Sun Jun 07, 2009 2:49 am
Current Project: The Awesome Game (Actual title)
Favorite Gaming Platforms: Cabbage, Ground beef
Programming Language of Choice: C++
Location: Rehovot, Israel

Re: Pause Function

Post by Netwatcher »

Is think you have to check wether you get an input from the keyboard, and that's it...

so just check if WM_KEYDOWN is true...

for more info http://msdn.microsoft.com/en-us/library/ms912654.aspx (on WM_KEYDOWN)
"Programmers are the Gods of their tiny worlds. They create something out of nothing. In their command-line universe, they say when it’s sunny and when it rains. And the tiny universe complies."
-Derek Powazek, http://powazek.com/posts/1655

blip.fm DJ profile - http://blip.fm/Noobay
current code project http://sourceforge.net/projects/vulcanengine/
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Pause Function

Post by eatcomics »

You just wait cyrax, your time is coming, did you get banned :). so you made a new account, time for IP ban :) loser... You don't know how to change your IP... I could get around that, but you're such a noob you wouldn't be able to, you'd probably go to your grandmas house and make a new account! :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol:
Image
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: Pause Function

Post by zodiac976 »

Who is this guy he sounds like an immature kid not getting
his way.
Post Reply