This is a discussion that's been going on on another board that I visit every now and again.
Code:
Poster1
.....
Now if someone can tell me how to take a single character
without requiring enter to be pressed, that'd also be ace.
Cheers.
Poster2
Well, the only function I know is getch()... not sure if it's the
best way to do it though, haven't done C code for aaaages
Azuth
getc, fgetc, getchar - getch() would likely work, but is not
standard.
Poster3
only on windows.. you need to do termios stuff on unix
like:
#include <termios.h>
struct termios term;
tcgetattr(0, &term)
term.c_lflag &= ~ICANON; // turn off cooked mode
term.c_cc[VMIN] = 0; // no minimum chars
term.c_cc[VTIME] = 0; // no hold-keys for time
tcsetattr(0, TCSANOW, &term)
// read one char/key from tty
i = read(0, &ch, 1);
tcsetattr(0, TCSANOW, &origterm) // restore original settings
Azuth
*Cough* *Hack* *Splutter*
You're saying that I can't read a single character under unix
using only ANSI C? Or did I miss something?
Now I'll admit the only code I've ever worked with on a *nix platform has been to do with quake, and I don't have a *nix box set up at home right now to try, so I may be mistaken, but surely I could write the code to read a single char in DOS in ANSI C, and compile that on a unix box & run it without much issue???