lvalue required as left operand of assignment with bool and ternary operator in C -


this question has answer here:

am going crazy here? ternary operator in function throwing 'lvalue required left operand of assignment error'

gsm_text_s *text_travers_find(const char* filename){      //linked list traversal logic finding , returning desired node      text_tmp = text_head;      bool name;      if(text_tmp){         (strcmp(filename, text_tmp->filename)) ? name = false : name = true;              while((!(name)) && (text_tmp->next)){                 text_tmp = text_tmp->next;             }     } else {         return text_tmp;     }     return text_tmp; } 

edit: instructed using ternary operator incorrectly.

it should be:

name = (strcmp(filename, text_tmp->filename)) ? false : true; 

another solution works, discovered in course of post being answered, not name value:

(strcmp(filename, text_tmp->filename)) ? (!name) : name; 

this work if name set desired default value.

thank you, everyone, answers, upvoted!!

whilst had written looks should work, you're treating more if/else construct is. it's expression should move assignment outside of this

name = (strcmp(filename, text_tmp->filename) ? false : true); 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -