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?
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])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With