How can i make this command? "Press any key to continue"

How can i make this command? "Press any key to continue"

I have a program, and i have for loop, i need it still working but all loop its finish it, i want the program give the user message "Press any key to continue".
and when the user press any key, the loop will work another loop.
http://www.cplusplus.com/forum/beginner/1988/page3.html#msg14102

The bottom of the code I posted will do it. Have fun!
I cant understand
I mean i want to make wile loop or for loop like this:
while(the commend)
{
....
}
I suggest you put the code in a separate function and call the function in your while loop.
You may also want to check out the FlushConsoleInputBuffer() to get rid of the key pressed.
hi ramishama,

just check it out this code... if u r having the access of <conio.h>
#include<conio.h>
main()
{
.........
while( ! kbhit())
{
printf(" key not yet pressed");
}
printf("key pressed");
...........
}
Last edited on
I always use "system( "Pause" );"
Both of you need to take a look through this thread:
http://www.cplusplus.com/forum/beginner/1988/

(which, BTW, I've already linked)
My DevC++ automatically puts system("PUASE"); into the file.. and I've already seen that it works on my platform. So I leave it in there, and use it while writing the program, testing and debugging.

It may be slow, but during these stages, my program still has debugging information anyway, so I know it's not running tip top shape.

But, by the time I'm done with the programming (usually even before I put in final steps), I'll have bypassed and even removed it, having put in something of my own. (usualy I don't even remove it. I just never let the program reach it.)

Usually, I put in a while (true) loop, and return out of it to exit the program only when the user asks for the program to quit. But then, most programs i've ran havn't been for single use only, and usually requires repeating the main function until the user is done for the day.

There are apps, I am sure that are meant to be run once.. usually with some sort of argument to a file that it should operate on, and once it's done, it needs not operate on that file anymore. When you create a program that does something like this, and you need to keep the window open so the user can view some sort of status or results in the console, then Duoas's code is probably best.
Last edited on
Topic archived. No new replies allowed.