Thak you.
"Keith Thompson" <ks***@mib.org> a écrit dans le message de news:
ln************@nuthaus.mib.org...
| Joona I Palaste <pa*****@cc.helsinki.fi> writes:
| > Jean Pierre Daviau <On**@waseno.ugh> scribbled the following:
| >> Hi every C one,
| >
| >> Which key entry (if there is any) should stop this loop?
| >
| >> #include <stdio.h>
| >> int main(){
| >> int c, getch(void);
| >
| >> while((c = getch()) != EOF){
| >> printf("%c\n", c);
| >> }
| >> return 0;
| >> }
| >
| > Well, to be pedantic about it, we don't know. getch() is not defined by
| > the ISO C standard, and thus it might return anything it wants. There
| > might be no way for it to ever return EOF. On the other hand, it could
| > return EOF after every keypress.
| > To be less pedantic, suppose getch() works the same way as getchar().
| > Then the answer is "it depends on your operating system". For example,
| > UNIX uses ^D, Windows uses ^Z, and AmigaOS uses ^\.
|
| In fact, there's a function getch() defined as part of the curses
| package available on Unix-like systems (and probably others). The man
| page (at least on one system I just checked) makes no mention of EOF.
| In fact, it's likely to be used in some kind of raw mode in which it's
| not possible to specify EOF (control-D probably comes through as a
| literal control-D character, '\004').
|
| I think Windows also defines a getch() function that does something
| different. I have no idea whether it ever returns EOF.
|
| To the OP: The fact that the getch() function had to be declared
| within the program should have been a clue that it's not declared in
| <stdio.h>, and that it's non-standard.
|
| If you want to write portable code, use fgetc(), getc(), or getchar()
| (your system's documentation should tell you how they differ). If
| you're curious about getch(), that's a system-specific question; if
| you can't find answers in your system's documentation, try a
| system-specific newsgroup.
|
| --
| Keith Thompson (The_Other_Keith)
ks***@mib.org
<http://www.ghoti.net/~kst>
| San Diego Supercomputer Center <*>
<http://users.sdsc.edu/~kst>
| We must do something. This is something. Therefore, we must do this.