Hello all
I'm wondering why getchar passes EOF character when pressing ctrl Z char, but getch gives 26?
Or getchar gives 10 value when the user presses enter key, and getch gives 13 value
Who knows?
Thank you
Hello all
I'm wondering why getchar passes EOF character when pressing ctrl Z char, but getch gives 26?
Or getchar gives 10 value when the user presses enter key, and getch gives 13 value
Who knows?
Thank you
'You see things; and you say "Why?" But I dream things that never were; and I say "Why not?"' ~ George Bernard Shaw, Back to Methuselah, Act I, Selected Plays with Prefaces, vol. 2, p. 7 (1949)
There isn't necessarily an "EOF character" (and there probably isn't). Rather, the CTRL+Z is to trigger the end-of-file condition, as if the end of the file has been reached, even though with interactive I/O on a command prompt, there isn't really the notion of a "file" as you might understand it. That you observed a character with the decimal value of 26 when using getch would indicate that the Windows command line might be using that character (or it may be the initial character of a sequence thereof) for that purpose. getchar, on the other hand, returns the constant named EOF specifically as a negative value (recall getchar returns an int) that is outside the range of possible characters (which are converted to unsigned char in the context of getchar).Originally Posted by Eshraghi6
This one is probably because getch is really giving you the character as-is, rather than translating the newline sequence (i.e., in Windows: carriage return followed by new line, hence decimal 13 followed by 10 in ASCII) into the equivalent of '\n' (i.e., new line, hence 10 in ASCII).Originally Posted by Eshraghi6
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)