Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to let a prognamm stop in random?

Posted on 1998-01-13
10
Medium Priority
?
203 Views
Last Modified: 2010-04-10
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?
Thanks
0
Comment
Question by:youngest
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 1178244
answer comming
0
 
LVL 22

Expert Comment

by:nietod
ID: 1178245
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.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1178246
I see you accepted the answer, but I suspect that (as it is) it wasn't enough.  Do you need more help?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:youngest
ID: 1178247
Thank you for helping me.
Can you help me?perhaps TSR can be solved this problem?
Do you think ?

0
 
LVL 22

Expert Comment

by:nietod
ID: 1178248
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?  
0
 

Author Comment

by:youngest
ID: 1178249
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 .
0
 
LVL 22

Expert Comment

by:nietod
ID: 1178250
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.
0
 

Author Comment

by:youngest
ID: 1178251
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
interrupt.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1178252
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())
{
   DoALittleSomething()
   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.
0
 

Author Comment

by:youngest
ID: 1178253
It IS GOOD!jUST What I need!Thank you!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question