how to quit

  • Thread starter mynameisthomasanderson
  • Start date
M

mynameisthomasanderson

Hi,
I'm pretty new to programming and i need a bit help from you, the
experienced programmers.
Well the thing is I'm making a small program on C. I want that
whenever user presses the key combination of ctrl+F3, he exits from
the program. how could I code this thing?
 
D

Daniel Rudy

At about the time of 3/27/2007 9:29 PM, (e-mail address removed)
stated the following:
Hi,
I'm pretty new to programming and i need a bit help from you, the
experienced programmers.
Well the thing is I'm making a small program on C. I want that
whenever user presses the key combination of ctrl+F3, he exits from
the program. how could I code this thing?

Well, to exit, you do exit(EXIT_SUCCESS) or exit(EXIT_FAILURE). As for
control key sequences, you will need to find out what characters are
generated when a user hits CTRL-F3, then have your program look for that
key sequence.


--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
 
C

CBFalconer

I'm pretty new to programming and i need a bit help from you, the
experienced programmers. Well the thing is I'm making a small
program on C. I want that whenever user presses the key combination
of ctrl+F3, he exits from the program. how could I code this thing?

Probably easier to have him hit CTL-C. You will probably not have
to do anything.
 
U

user923005

Hi,
I'm pretty new to programming and i need a bit help from you, the
experienced programmers.
Well the thing is I'm making a small program on C. I want that
whenever user presses the key combination of ctrl+F3, he exits from
the program. how could I code this thing?
From the C-FAQ:

19.5: How do I read the arrow keys? What about function keys?

A: Terminfo, some versions of termcap, and some versions of curses
have support for these non-ASCII keys. Typically, a special key
sends a multicharacter sequence (usually beginning with ESC,
'\033'); parsing these can be tricky. (curses will do the
parsing for you, if you call keypad() first.)

Under MS-DOS, if you receive a character with value 0 (*not*
'0'!) while reading the keyboard, it's a flag indicating that
the next character read will be a code indicating a special key.
See any DOS programming guide for lists of keyboard scan codes.
(Very briefly: the up, left, right, and down arrow keys are 72,
75, 77, and 80, and the function keys are 59 through 68.)

References: PCS Sec. 5.1.4 pp. 56-7.
 
S

SM Ryan

(e-mail address removed) wrote:
# Hi,
# I'm pretty new to programming and i need a bit help from you, the
# experienced programmers.
# Well the thing is I'm making a small program on C. I want that
# whenever user presses the key combination of ctrl+F3, he exits from
# the program. how could I code this thing?

Whether you want to poll for keypress or arrange some kind of
interrupt handler, you'll need a system specific function. What you're
going to get from ANSI C by itself is to stop the program until
input is available and then check the input characters. So it's going
to depend on the operating system and/or the windowing system.
 
T

Thomas Dickey

19.5: How do I read the arrow keys? What about function keys?
A: Terminfo, some versions of termcap, and some versions of curses

oh. "some versions of termcap" is a little odd (can anyone point
to a version of termcap that does not?).

most versions of curses as well - but this isn't the first inaccuracy
we've seen in the FAQ.

regards.
 
U

user923005

oh. "some versions of termcap" is a little odd (can anyone point
to a version of termcap that does not?).

most versions of curses as well - but this isn't the first inaccuracy
we've seen in the FAQ.

If you have proof that there are no exceptions, then send an email to
Steve and he will correct it, I imagine.
I guess that there is at least one exception in either case.
Of course, both statements are mathematically true, because 'some' is
a subset of 'all'.
In any case, it's a nit.
 
T

Thomas Dickey

user923005 said:
If you have proof that there are no exceptions, then send an email to
Steve and he will correct it, I imagine.

He said he would the last time I pointed out an error.
He didn't correct it.
I guess that there is at least one exception in either case.
Of course, both statements are mathematically true, because 'some' is
a subset of 'all'.
In any case, it's a nit.

hmm - no. It's incorrect, and (even given the old information that he
used), was never correct since the FAQ was written.
 
K

Kenny McCormack

Thomas Dickey said:
He said he would the last time I pointed out an error.
He didn't correct it.
[...]

He is but human. Consider trying again.

The implication is that this was not a one time occurrence.

My reading of Thomas's text is that he has pointed out several errors
over the years, and that, on at least one occasion, Steve explicitly
said that it would be fixed, but nothing happened. Hence the loss of
faith.
 
D

Default User

Thomas said:
Richard Tobin said:
email to >>>> Steve and he will correct it, I imagine.



Read the page (obviously you either did not, or the implication of
extensive discussion was too elusive ;-).


Yeah, so? Besides not seeing anything in there relevant to what you
say, the copyright holder can't make it more restrictive than the law
allows.




Brian
 
K

Keith Thompson

Thomas Dickey said:
btw, his copyright precludes any extensive discussion.

http://c-faq.com/copyright.html

Here's what that page currently says (I'm going to assume that quoting
it is covered under fair use):

This collection of hypertext pages is Copyright 1995-2005 by Steve
Summit. Content from the book "C Programming FAQs: Frequently
Asked Questions" (Addison-Wesley, 1995, ISBN 0-201-84519-9) is
made available here by permission of the author and the publisher
as a service to the community. It is intended to complement the
use of the published text and is protected by international
copyright laws. The on-line content may be accessed freely for
personal use but may not be published or retransmitted without
explicit permission.

I see nothing there that precludes discussion, unless you assume that
discussion requires quoting substantial parts of the FAQ. Since the
FAQ is well indexed, a great deal of discussion can take place using
question numbers or hyperlinks.

I Am Not A Lawyer.

Re-posting the entire FAQ would fairly clearly be a copyright
violation. Citing individual questions presumably would not. Quoting
portions of it might or might not fall under fair use, depending on
the size of the quotation and on other factors about which, not being
a lawyer, I won't speculate.

Steve has tended to be reasonably generous in allowing use of the FAQ,
at least as generous as his publisher allows him to be. People have
occasionally quoted entire pages here, with no complaint from Steve.
(Personally, I prefer just to cite question numbers, not just to avoid
copyright infringement, but because it encourages readers to browse
nearby portions of the document.)
 
K

Kenneth Brody

Thomas said:
He said he would the last time I pointed out an error.
He didn't correct it.


hmm - no. It's incorrect, and (even given the old information that he
used), was never correct since the FAQ was written.

I, presonally, have used versions of termcap that had no concept
as "function keys" (ie: F1, F2, and so on). Of course, that was
some 20 years ago, and the modern implementations that I have seen
have entries for such keys. Whether any versions still exist that
do not support them, I cannot say.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
T

Thomas Dickey

I, presonally, have used versions of termcap that had no concept
as "function keys" (ie: F1, F2, and so on). Of course, that was
some 20 years ago, and the modern implementations that I have seen
have entries for such keys. Whether any versions still exist that
do not support them, I cannot say.

hmm. termcap stores the whole entry as a string. Function keys and
other capabilities are string-capabilities with conventional (not
standardized) names. So any termcap file can represent function keys.

That is, unless you were using some highly advanced technology which
deduced that some capability names referred to function keys and
prevented you from using them.

If that's the case, you should elaborate on it.

More likely, you simply did not know.

termcap, when I first encountered it in the early 80's was certainly
capable of representing function keys. It was taken for granted that
termcap could represent anything that an application needed from a
terminal.

Curses did not necessarily have a parser for those (as I recall writing
one in late 1983/early 1984 to make BSD 4.3's curses more palatable with
a couple of terminals for some applications that used both cursor-keys
and function-keys).

Here's one -

http://vt100.net/annarbor/aaa-ug/section4.html#S4.1
 
K

Kenneth Brody

Thomas said:
hmm. termcap stores the whole entry as a string. Function keys and
other capabilities are string-capabilities with conventional (not
standardized) names. So any termcap file can represent function keys.

Okay, let me clarify...

What I meant was that there were no standardized entries for such
keys. So, unless you wanted to write custom termcap entries for
every terminal you wanted to support, you were stuck with the
standard, defined entries. Current versions appear to have
defined a standard set of entries for these keys.

On the other hand, current versions of termcap are often simply
wrappers to terminfo routines, and terminfo is not extensible. If
the entry wasn't defined by the implementor of the library, you
cannot add it.

Now, we defined our own entries for the functionality we wanted to
support, and wrote a wrapper around the termcap routines that could
use both the /etc/termcap file (or $TERMCAP), plus our application-
specific termcap file stored elsewhere. This allowed us to simply
enhance the existing termcap file, rather than replace it.

Of course, all of this is OT for clc. On the other hand, writing
a termcap library would probably be topical for clc, as you could
implement it in ANSI C, AFAIK. After all, it's just some functions
which read and parse a text file, and then use that info to send
things to stdout.

[...]

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
T

Thomas Dickey

Okay, let me clarify...

You didn't have to (the time would have been better spent by checking).

BSD 4.2 (I see the file's date July 1, 1983 - more than 20 years)
distributed a termcap with k1, k2, etc., in its entries. A quick check
shows 35 entries with _that_ much use of function keys.

That convention is still in use. You may not have used or even been
aware of it (there were manpages...), but other people used it, and
assumed it.
 
T

Thomas Dickey

Kenneth Brody said:
Of course, all of this is OT for clc. On the other hand, writing

I'm afraid not:
discussing inaccuracies in a newsgroup's faq is always on topic.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top