-2

I am trying to implement a function that compares two strings. However, i am getting "expression must be a modifiable lvalue" in function strcmp even if i use char pointers instead of char array. My code is in following.

typedef enum { false, true } boolean;

struct threeGram *threeGram_array;

struct threeGram
{
    const char *value;
    int occurence;
};

boolean containsValue(struct threeGram array[], const char *string){

    int i;
    for(i = 0; i < sizeof (array) / sizeof (struct threeGram); i++){
        if(strcmp(array[i].value, string) = 0){
            return true;
        }
    }
    return false;
}

1 Answers1

1

When checking for equality in C you should use double equals == otherwise this is interpreted as assignment. Thus on this line:

if(strcmp(array[i].value, string) = 0){

You try to assign a result to function return value which is non-modifiable lvalue.

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176