I'm learning pointers in C++, while not as clear as I'd like to be on the subject, I'm slowly getting there.
My goal here was to write a function using pointer notation, to go through an array and change the case of the input.
For example
("ab7d") myToUpper() -> AB7D
Here is my idea for accomplishing this.
void myToUpperCase(const char *source, char *dest)
{
for (int i = 0; *(source + i) != '\0'; i++)
{
*(dest + i) = toupper(* (source + i));
}
}
Results
("ab7d") myToUpper() -> AB7D\377
Would someone mind explaining the reasoning behind \377
being added to the output, obviously I'm looking for just the source to be changed here with nothing else added to the output.
Thanks