My instructors give me the following function. So don't blame me for ambiguity lol
void step_step_step(char *first, char *second, char *third)
{
if (third[3] == second[2] + 8 && second[2] == first[1] + 8)
printf("8: Illinois\n");
else
printf("8: ERROR\n");
}
I try to call the function in the this way:
char *p8_1 = (char*) malloc(sizeof(char)*11);
char *p8_2 = (char*) malloc(sizeof(char)*11);
char *p8_3 = (char*) malloc(sizeof(char)*11);
p8_1[9] = 'u';
p8_2[2] = p8_1[9];
p8_2[10] = p8_1[9];
p8_3[3] = p8_2[10];
step_step_step(p8_1, p8_2, p8_3);
And it keeps printing error. What am I doing wrong here? I don't understand why that doesn't work when my other solution does:
p8_2[2] = p8_1[1] + 8;
p8_3[3] = p8_2[2] + 8;
step_step_step(p8_1, p8_2, p8_3);
+and&&+operators are adding characters, not pointers, so there's no "pointer addition" here. Instead you're comparing'u'to'u' + 8and getting non-equal (not suprisingly)