Reputation: 9
I tried to write this thing in C:
(*(result+1))!="\0"
The compiler said:
Possible assignment in condition
(*(result+1))=!"\0"
What is the problem?
Upvotes: 0
Views: 102
Reputation: 224854
Comparisons in C use the ==
operator. The single =
is an assignment. Besides that, you're trying to compare a pointer to an integer. The code you have is:
(*(result+1))=!"\0"
In that expression, !"\0"
is equal to 0
, so your code is really doing:
(*(result+1))=0
And that's probably not what you want. For sure it doesn't match what you have there in your "I'm trying to write this expression" example. I think what you are trying to do is:
(*(result+1)) != '\0'
Using the !=
"not equal to" operator. It just looks like you have written =!
instead. Probably just a typo. Note that I changed the double quotes to single quotes to correct your expression, too.
Editorial note - you don't need the operator at all. Your expression is equal to:
*(result + 1)
Which would have saved you the trouble in the first place.
Upvotes: 7
Reputation: 10685
If you are indeed performing a comparison and not an assignment, you need ==
instead of =
; that is why you're getting the possible assignment message.
Upvotes: 1