Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!iuvax!silver!rschmidt From: rschmidt@silver.ucs.indiana.edu (roy schmidt) Newsgroups: comp.lang.c Subject: Re: how do I do a 'readln' in C ?? Summary: KISS Message-ID: <45851@iuvax.cs.indiana.edu> Date: 26 May 90 03:36:32 GMT References: <1382@sumax.UUCP> <1990May16.064747.22020@iesd.auc.dk> <196@taumet.COM> Sender: root@iuvax.cs.indiana.edu Organization: Indiana University, Bloomington IN. Lines: 34 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 | | Indiana University | /* They are _my_ thoughts, | | Graduate School of Business | and you can't have them, < > Bloomington | so there! */ X ___________________________________________________________ X