in my main function I initialize a char pointer. This pointer I overgive a function setMemory(char *ptr) as a parameter where some memory shall be allocated. Additionally some data shall be stored in this function. Back in main function I try to read out the data to which the pointer shows, but not the correct data were outputted. Why?
int main(int argc, char *argv){
char *ptr;
setMemory(ptr);
printf("String: %s", ptr); //Should print c
return 0;
}
void setMemory(char *ptr){
ptr = (char*)malloc(sizeof(char)*10);
*(ptr) = 'c';
}