Yesterday I was very tired and I was very sleepy; of course i intend
"scanf" and no "fscan" or "fgets". The code above i have not compiled
so it is not tested as well as i wrote.
I think it is not possible to get by "scanf" something as a simple
return or an f(1-12) or an escape,
Use the "%c" format to read a single character. If you want it to only
read in a new-line, but to put any other character back into the
read-buffer, then use the scanset feature: "%1[\n]". Using getchar() and
ungetc() is much simpler way to do this, but you did specify that you
wanted to use scanf().
There's no portable way to identify escape sequences and function keys,
but for any given platform you could use "%c" to read in a character at
a time, and then type the keys that you want it to identify, and find
out how they are represented. Keep in mind that some keys may be
represented by multiple characters.
... as well as anyone of you say. The
";" at the end is intend simply as "end" and i use it simply to
improve reading (as well as in Pascal, you might to write always ";").
No other i intend.
There are many places where you can safely insert a ';' without causing
problems - but be careful not put it anywhere where it doesn't belong,
or would change the meaning of your code. However, inserting a ';' in
places where it doesn't make any difference is going to leave people
suspecting that you don't realize that it's not needed, which is going
to make them very worried about your competence as a C programmer. As
long as you're a newbie, I suppose that's not a bad thing, but I'd
recommend dropping the habit. For experienced C programmers, spurious
';' characters do NOT improve reading.
Ok, now i formulate the question in other way:
How can i make a program in manner that i can stop it at the prompt
with ESC, in manner that it can reading a simple return, in manner
that i can set function keys to make something, etc..........?
If no with "scanf", what can i use?
A key problem you need to deal with is buffering. With an unbuffered
stream, as soon as a char becomes available, it can be read by C
character input functions like fgetc(). With line buffering, C input
functions can't retrieve anything until an entire line has been typed
and return has been hit. With full buffering, C input functions do not
see anything until the entire buffer has been filled. C allows full
buffering only if the implementation can be certain that it's not
reading from an input device. Therefore, if stdin is your console, at
worst you're getting line buffering. Unfortunately, what you want is
unbuffered input, and that's not guaranteed - line buffering is much
more common. You can try to make stdin unbuffered by using setbuf(stdin,
NULL), but check for an error return - the standard does not guarantee
that the buffering can be changed. The setbuf() call must occur before
any attempt is made to read from stdin.