I wrote a more complex program, but I narrowed down my problem to the following: Why does this program print garbage and not hzllo? I followed the values ββand memory address of temp and p with a debugger, and it returns correctly from the foo function, and for some reason I donβt understand what is happening with the fingerprints.
void foo(char **str) { char temp[79]; strcpy_s(temp,79,*str); *(temp + 1) = 'z'; *str = temp; } void main() { char *p = (char*) malloc(79 * sizeof(char)); p = "hello"; foo(&p); printf("%s", p); }
source share