I am not understanding why this code is wrong, it says lvalue required as increment operand. But isn't planets an array of pointers to strings? so isn't planets++ supposed to take me to the next string. example- planets is a pointer to the string "mercury". When I do planets++ shouldn't it take me to "venus"
#include <stdio.h> int main() { char* planets[] = {"Mercury", "Venus", "Earth","Mars","Jupiter", " Saturn", "Uranus", "Neptune", "Pluto"}; int count = 0; for(planets; planets <= planets + 8;planets++){ if(**planets == 'M'){ count++; }// if }// for printf("\n%d",count); }
Saturnintentional?planetsis an array of pointers to strings. thus,if(**planets == 'M')is wrong. You might need another pointer which points to the pointer arrayplanets. Note**planetsis a pointer namedplanetsto another pointer, which isn´t the case here.