Click here to Skip to main content
15,748,615 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want reset my program. for example if I press key R my program start from begin
how can I do that ?


For a console application:
At the top of your code file, add this:
#include <conio.h>

In your main method:
bool stop = false;
while (!stop)
      system("cls"); // clear console
      // run your program
      int pressedChar = getch();
      stop = pressedChar != 114; // 114 = 'R'
return 0;

For a Windows application:
Have a look here:[^]
How To Create a Self-Restartable Application[^]

Hope this helps.
Share this answer
Abhishek Pant 23-Dec-12 8:45am    
Thomas Daniels 23-Dec-12 8:46am    
Thank you!
mohammadali1375 23-Dec-12 9:20am    
thanks. but my program is'n a console program. its a 2d game with sdl and have alot of class and vars. i want after the game end , my program re start for play again.
Thomas Daniels 23-Dec-12 9:21am    
Thanks for your reply!
I'll try to find how to restart a Windows application.
mohammadali1375 23-Dec-12 9:55am    
Thanks for your help
You need to add a method to your main class that purges all views and documents and resets all control variables to their initial state. However, only you know what those things are.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900