how to let a prognamm stop in random?

Dear Sir:
  I have written a prognamm.I want to add a function let it
stop in random,I mean when I pressa key it should stop.
When I press another key it should run again.How to do?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

answer comming

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
basically it is impossible to stop (suspend) a program.  (actually it is often possible to suspend a program on a multi-tasking operating system.  But how to do so is system-dependant and not what you want.)

Since it is impossible--fake it.

don't stop the program, instead make it appear stopped by having it execute a loop that does (almost) nothing.  Actually the loop can't do nothing or it will never end.  The loop should look for the key press that should allow the program to continue.

next problem, where do you put the loop?

That depends on you program.  If you program has a single central procedure for obtaining user input (like most windows programs, as well as others) then you can put the code to start the loop there.  Otherwise, you may need to alter the code at every location that does user input.

I can't provide more help without knowing more about your program its purpose and its design.  

If you need more, post some more information.
I see you accepted the answer, but I suspect that (as it is) it wasn't enough.  Do you need more help?
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

youngestAuthor Commented:
Thank you for helping me.
Can you help me?perhaps TSR can be solved this problem?
Do you think ?

A TSR could be used to suspend a DOS program.  But it seems like a very poor solution.  It is very system dependent.  What is it exactly that you are trying to do?  
youngestAuthor Commented:
Thank you for helping me.I plan to write a demo prognamm,I should let it stop when it is needed to stop.then press any key it should continue to run .
But why can't the program itself look for the key and enter a wait loop whent he key is pressed?  Doesn't that seem like a more natural design than envoking a TSR to suspend the program?  It is also more portable and as well as more extensible.
youngestAuthor Commented:
In BC++,how to realize stop?use getch()?I tried to do but failed.
Can you tell me?The computer can't correspond with this keyboard

You do not mean keyboard interrupt?  right.  I don't think you need to hook the keyboard interrupt and if you do you don't use getch().

you could do something like the following which holds up a loop whenever 'P' is typed.  The loop continues again when 'P' is typed again.

while (NotDoneDoingSomething())
   if (_kbhit()) // If a key has been typed, then
       if (_getch() == 'P')
          while (_getch() != 'P');

Does this help?  I'm having a hard time understanding your situation.  If this doesn't help explain in more detail what it is your trying to do.
youngestAuthor Commented:
It IS GOOD!jUST What I need!Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.