Changing memory address of a char*
Posted
by
Randall Flagg
on Stack Overflow
See other posts from Stack Overflow
or by Randall Flagg
Published on 2012-09-16T09:23:46Z
Indexed on
2012/09/16
9:37 UTC
Read the original article
Hit count: 237
I have the following code:
str = "ABCD"; //0x001135F8
newStr = "EFGH"; //0x008F5740
*str
after realloc at 5th position - //0x001135FC
I want it to point to: 0x008F5740
void str_cat(char** str, char* newStr)
{
int i;
realloc(*str, strlen(*str) + strlen(newStr) + 1); //*str is now 9 length long
// I want to change the memory reference value of the 5th char in *str to point to newStr.
// Is this possible?
// &((*str) + strlen(*str)) = (char*)&newStr; //This is my problem (I think)
}
© Stack Overflow or respective owner