OK, sorry for the bad pun: P
I coded the old trick HAL => IBMin C. I just read the first few pages in K & R and I thought it would be a good first game with them.
char evil[] = "HAL";
char *ptr = evil;
for (int i = 0; i < strlen(evil); ++i, ++ptr) {
(*ptr)++;
}
printf("%s\n", evil);
My problem is that I have two variables increasing, iand ptr, and something tells me that one of them is redundant (maybe I still don't think enough C).
The only reason I use iis to determine if we read the end of the line. Is there a way to check the pointer to see if it has arrived at the end of the line?
Update
Sorry for any confusion on the valid question. If I missed what I basically had in mind, why use a pointer when I need an incremental index to check the length. I could just use this index to index the right char from an array.
source
share