rschmidt@silver.ucs.indiana.edu (roy schmidt) (05/26/90)
In article <196@taumet.COM> steve@taumet.UUCP (Stephen Clamage) writes: >In article <1990May16.064747.22020@iesd.auc.dk> kjeld@iesd.auc.dk (Kjeld Flarup) writes: >>In article <1382@sumax.UUCP> cadwell@sumax.UUCP (James A. Cadwell) writes: >>>Simple question which I hope has a simple answer: how does one consume an >>>in put line in C. Pascal wise it's 'readln'. >>> >>>thank you, Jim >>This is my simple solution. It reads until it encounters a eoln, EOF or fills >>the buffer > >Well, a standard C function does precisely this, with no code to write. > char *fgets(char *s, int n, FILE *f); >"s" is an array to fill, and at most n-1 characters >will by copied from file "f", but not beyond a newline or EOF (the newline >is in the buffer as a '\n' character). The string in "s" is always >terminated by a null character. "fgets" returns null pointer on error, >"s" otherwise. Maybe so, but even simpler is: int c; while ((c = getchar()) != EOF && c != '\n') ; c = getchar(); And the input line is gone. Oh, you meant you want to keep the input line? Arf Arf. ----------------------------------------------------------- ^ Roy Schmidt | #include <disclaimer.h> | | Indiana University | /* They are _my_ thoughts, | | Graduate School of Business | and you can't have them, < > Bloomington | so there! */ X ___________________________________________________________ X