how to quit

T

Thomas

Hi,
Thanks to those who replied to my question.
Well the actual thing is when i make a program in C,user can only exit
from it when that particular code lie is executed.
In that line i use any suitable input function then i compare it using
if function. there if condition is true, it exits otherwise not.
Now i want this capability that user doesn't have to wait for that
particular line to be executed.
Whenever he presses a particular key, lets say Q, my program picks it,
compares and exit.
I mean that such function would be running in the background
simultaneously with other functions or lines of my program.
Is it possible and how?
 
B

Bill Pursell

Well the actual thing is when i make a program in C,user can only exit
from it when that particular code lie is executed.
In that line i use any suitable input function then i compare it using
if function. there if condition is true, it exits otherwise not.
Now i want this capability that user doesn't have to wait for that
particular line to be executed.
Whenever he presses a particular key, lets say Q, my program picks it,
compares and exit.
I mean that such function would be running in the background
simultaneously with other functions or lines of my program.
Is it possible and how?

It is possible, but the mechanism to accomplish it will
depend on the system you are using and it cannot be
done portably. You must use things that are outside of
the C language itself. (eg [n]curses and/or threads.)
You will get better responses if you post your question
to a group dedicated to the system on which you are
trying to accomplish this task. Although, as has
been mentioned, you might find it easier to use the
mechanism provided by your system for terminating
you process. For example, on most (probably all)
unix-like systems, ctrl-C (or some other keystroke)
will send a signal to the foreground process (your
program). By default, your program will terminate
when it receives that signal, but you can catch
the signal and take other actions if you wish. However,
that is outside the scope of the language itself, and
you should really take the question to a system specific
news group.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top