Home > Blockchain >  Function LValue in C Return Not Specified [closed]
Function LValue in C Return Not Specified [closed]

Time:09-16

I am trying to organize a C program and then generate a lex file. But there is one last error in the code that I don't understand

I have never worked with C before.

The first part of the code with the error:

/* addChar - a function to add nextChar to lexeme */
void  addChar() {
  if  (lexLen <= 98) {
    lexeme[lexLen  ] = nextChar;
    lexeme[lexLen] = 0;
  }
  else
    printf("Error - lexeme is too long \n");
}

/* getChar - a function to get the next character of 
             input and determine its character class */
 void getChar() {
   if  ((nextChar = getc(in_fp)) = EOF) {
     if  (isalpha(nextChar))
      charClass = LETTER;
     else if  (isdigit(nextChar))
           charClass = DIGIT;
          else  charClass = UNKNOWN;
   }
   else
     charClass = EOF;
}

The Error is:

program.c: In function ‘getChar’:
program.c:96:34: error: lvalue required as left operand of assignment
    if  ((nextChar = getc(in_fp)) = EOF) {```

CodePudding user response:

This:

if  ((nextChar = getc(in_fp)) = EOF) {

Should be

if  ((nextChar = getc(in_fp)) == EOF) {
                              ^^

This changes the expression from an assignment to an evaluation, thus removing the need for an lvalue

  •  Tags:  
  • c
  • Related