3

For some reason, I'm getting an error at this line:

while ((en = strtok(NULL, " " ) !=NULL)){ //do something }

and at this line (the error for this one is 'comparison between pointer and integer ('int' and 'void *'), even though inputString is a char array and null is null.

while (!inputString[i]==NULL)

en is a char, and was declared as char *en. I'm not sure why...is it because I can't compare them with NULL?

1 Answer 1

13

The problem isn't the comparison - it's the assignment. != has higher precedence than =, so your expression is parsed as:

en = (strtok(NULL, "") != NULL)

presumably en is a pointer type, and the result of != is an int, so that's where the warning arises. You probably meant:

(en = strtok(NULL, "")) != NULL

as the condition. The same is true in your second example - ! has higher precedence than ==, so you're comparing the result of !inputString[i] (which has type int) to NULL (which may have type void *). You might have meant:

while (!(inputString[i] == NULL))

which can also be written as:

while (inputString[i] != NULL)

or just

while (inputString[i])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.