Hi all, I am new to C and am having a memory allocation problem. I am creating a char* and initializing to NULL, then passing it to another function which allocates some memory for it, and copies some characters. When the second function returns, my char* returns to NULL. I'm sure I am missing something simple here but cannot figure it out. Any help would be greatly appreciated. See the example code below:
Code:
void functionA() {
char *text = NULL;
functionB(text);
//variable text is still NULL
}
void functionB(char *text){
char *tempText = "12345";
size_t len = strlen(tempText);
text = (char*)malloc(len * sizeof(char) + 1);
strcpy(text, tempText );
}