I made a function to convert an array of ints (a zipcode) into a cstring. If I call the function, the return is gibberish, but if I cout the returned variable inside the function it's exactly as expected.
const char* print_zip(const int* zip) {
char output[6];
char* ctemp = output;
const int *itemp = zip;
for (int i = 0; i < 5; i++) {
*ctemp = *itemp + 48; // convert to char numbers.
itemp++; // iterate using pointers rather than []
ctemp++; // per assignment specifications
}
*ctemp = '\0';
std::cout << output << std::endl; // (debug only) as expected
return output; // cout << print_zip(); not as expected
}