OK, sorry about the bad pun :P
I've coded the old trick of HAL => IBM
in C. I've just read the first few pages in K&R reguarding them, and I thought it would be a good first play with them.
char evil[] = "HAL";
char *ptr = evil;
for (int i = 0; i < strlen(evil); ++i, ++ptr) {
(*ptr)++;
}
printf("%s\n", evil); // IBM
My problem is, I have two variables incrementing, i
and ptr
, and something is telling me one of them is redundant (perhaps I'm still not thinking C well enough).
The only reason I use i
is to determine if we have read to the end of the string. Is there any way to check the pointer to see if it has arrived at the end of the string?
Update
Sorry for any confusion of the actual question. By have I missed the point I basically meant, why would I use a pointer when I needed an incrementing index to check the length as well. I could just use that index to subscript the right char from the array.