Here’s the deal. I have a large character array and am trying to manipulate it. Here’s some code I was using to test the idea:
#include <stdio.h>
char r[65536],*e=r;
main() {
e+=8;
while(*e) {
*e+=1;
e+=5;
*e-=1;
e-=1;
}
*e+=1;
printf("%i",*e);
printf(" %c",e);
}
What it’s supposed to do is:
- Set the first element to 8
- Then, while the current element is not zero,
- Move to the next cell
- Add 5 to it
- Move back
- Subtract one. (This repeats 8 times because the while test will fail when it has subtracted the last one)
- Display the location of the pointer
- Display the contents of the array that the pointer points to (I hope)
What it does:
1 Φ
as opposed to
40 (
^^ 8 x 5 = 40, so that’s what it should display.
Any tips/suggestions/criticism accepted.
You’re dereferencing exactly where you should not and vice versa. What you meant to do was:
*retrieves the value the pointer points to.