lvalue required as left operand of assignment with bool and ternary operator in C -
this question has answer here:
- errors using ternary operator in c 4 answers
- ternary operator in c vs c++ [duplicate] 3 answers
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
Post a Comment