* Stig Brautaset <[EMAIL PROTECTED]> spake thus: > * Sebastiaan <[EMAIL PROTECTED]> spake thus: > > High, > > > > > > On Sun, 4 Nov 2001, J.A.Serralheiro wrote: > > > > > hi. Im trying to read a complete line from a text file. > > > I use the fscanf( file, "[^\n]",buffer); butit doesnt work. I reads the > > > entire file until overflow of the buffer. > > > > > > Can some one tell me how? > > > > > > I read scanf manual, but it wasnt of much help, for me at leastr. > > > > > >From an old proggie I wrote once: > > while (fgets(buff, sizeof(buff)-1, filestream) != NULL) > > { > > /* do something with the 'buff' variable */ > > }
Oups, just correcting a few errors: > > void f(char *s, int lim); int f(char *s, int lim); > > #define LEN 80 > int main(void) > { > char s[LEN]; > > f(s, LEN); > puts(s); if (f(s, LEN) == 0) puts(s); > > return 0; > } > > void f(char *s, int lim) > { > FILE *fp; > > if (!(fp = fopen("filename", "r"))) { > puts("error opening file"); > return -1; > } > > fgets(s, lim, fp); return 0; > } Regards, Stig -- brautaset.org Registered Linux User 107343