home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11630 < prev    next >
Encoding:
Internet Message Format  |  1992-07-26  |  1.7 KB

  1. Path: sparky!uunet!darwin.sura.net!convex!egsner!lerami!taoami!robertk
  2. From: robertk@taoami.lerctr.org (Robert Kesterson)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: While problem
  5. Distribution: world
  6. Message-ID: <robertk.02w2@taoami.lerctr.org>
  7. X-NewsSoftware: GRn 1.16e (7/4/92) by Mike Schwartz & Michael B. Smith
  8. Date: 26 Jul 92 20:47:23 CDT
  9. Organization: Not an Organization
  10. Lines: 38
  11.  
  12. In article <92204.160015GNR100@psuvm.psu.edu> <GNR100@psuvm.psu.edu> writes:
  13. >    I'm having trouble with a whil loop in function I am writing to
  14. > read a line from a fileby puttingeach character into an array, accesed by
  15. > pionters, until the '\n' character is reached of EOF is reached.
  16. >   Trouble is, I keep getting an error message that the function needs an
  17. > Lvalue (address) inside the while loop.  Any ideas as to the problem?
  18. > The filename is a global variable, and that's why it isn't declared.
  19. >
  20. >                 gnr100@psuvm.psu.edu
  21. > ------------------------Begin Code-------------------------------------------
  22. > char readline(char *string[])
  23. > {
  24. >   int i=0;
  25. >
  26. >   while(((*string+i++=(char)getc(fname))!=EOF)
  27. >       &&((*string+i++=(char)getc(fname))!='\n'));
  28. >   return (*string+(i-1));
  29. > }
  30. >
  31.  
  32. Try adding one more set of parentheses.  You're adding what's in (*string) to the
  33. integer i, thereby producing an integer value.  Then you're trying to assign
  34. a character to it, which won't work since the integer isn't an lvalue.
  35. Try it like this (note the extra parentheses around (string+i++) :
  36.  
  37.  char readline(char *string[])
  38.  {
  39.    int i=0;
  40.  
  41.    while(((*(string+i++)=(char)getc(fname))!=EOF)
  42.            &&((*(string+i++)=(char)getc(fname))!='\n'));
  43.    return (*string+(i-1));
  44.  }
  45.  
  46. --
  47.  
  48. ======================================================
  49.  Robert Kesterson         robertk@taoami.lerctr.org
  50.