home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!darwin.sura.net!convex!egsner!lerami!taoami!robertk
- From: robertk@taoami.lerctr.org (Robert Kesterson)
- Newsgroups: comp.lang.c
- Subject: Re: While problem
- Distribution: world
- Message-ID: <robertk.02w2@taoami.lerctr.org>
- X-NewsSoftware: GRn 1.16e (7/4/92) by Mike Schwartz & Michael B. Smith
- Date: 26 Jul 92 20:47:23 CDT
- Organization: Not an Organization
- Lines: 38
-
- In article <92204.160015GNR100@psuvm.psu.edu> <GNR100@psuvm.psu.edu> writes:
- > I'm having trouble with a whil loop in function I am writing to
- > read a line from a fileby puttingeach character into an array, accesed by
- > pionters, until the '\n' character is reached of EOF is reached.
- > Trouble is, I keep getting an error message that the function needs an
- > Lvalue (address) inside the while loop. Any ideas as to the problem?
- > The filename is a global variable, and that's why it isn't declared.
- >
- > gnr100@psuvm.psu.edu
- > ------------------------Begin Code-------------------------------------------
- > char readline(char *string[])
- > {
- > int i=0;
- >
- > while(((*string+i++=(char)getc(fname))!=EOF)
- > &&((*string+i++=(char)getc(fname))!='\n'));
- > return (*string+(i-1));
- > }
- >
-
- Try adding one more set of parentheses. You're adding what's in (*string) to the
- integer i, thereby producing an integer value. Then you're trying to assign
- a character to it, which won't work since the integer isn't an lvalue.
- Try it like this (note the extra parentheses around (string+i++) :
-
- char readline(char *string[])
- {
- int i=0;
-
- while(((*(string+i++)=(char)getc(fname))!=EOF)
- &&((*(string+i++)=(char)getc(fname))!='\n'));
- return (*string+(i-1));
- }
-
- --
-
- ======================================================
- Robert Kesterson robertk@taoami.lerctr.org
-