Reputation: 25
When I call this function I get the error even though they are being used. Can someone explain:
pointers.c:30:5: warning: expression result unused [-Wunused-value] *a++; ^~~~ pointers.c:39:9: warning: expression result unused [-Wunused-value] *s++; ^~~~ pointers.c:40:9: warning: expression result unused [-Wunused-value] *b++; ^~~~ pointers.c:48:7: warning: expression result unused [-Wunused-value] *s++; ^~~~
int strend(char *s, char *b){
char *temp = b;
while(*s != '\0'){
if(*s == *b){
while(*s == *b && *b != '\0' && *s != '\0'){
*s++;
*b++;
if(*b == '\0')
printf("wrong");
printf("compare: %c, %c\n", *s, *b);
printf("equal: %d\n", *s == *b);
}
}
else{
*s++;
}
printf("check %c, %c\n", *s, *b);
if(*b == '\0' && *s == '\0'){
return 1;
}
else{
b = temp;
}
if(*s == '\0')
printf("bazinga");
}
return 0;
}
Upvotes: 1
Views: 1951
Reputation: 409404
You dereference the pointer too, not only incrementing it. That dereference will give you the value pointed to by the old pointer (before the increment) but you don't use that value, leading to the warning.
Simple solution? Don't use the dereference operator *
.
Upvotes: 5