A
Angus
Hello
I am passing a char* pointer into a function and in the function I malloc
but when the function returns the pointer seems to go out of scope? I
thought that if I passed a pointer, then I would allocate memory to the
pointer? What am I doing wrong?
#include <stdlib.h>
void doit(char* allostring)
{
allostring = malloc(6);
memcpy(allostring, "Hello\0", 6);
}
int main()
{
char* strtopass = 0;
doit(strtopass);
free(strtopass);
return 0;
}
I am passing a char* pointer into a function and in the function I malloc
but when the function returns the pointer seems to go out of scope? I
thought that if I passed a pointer, then I would allocate memory to the
pointer? What am I doing wrong?
#include <stdlib.h>
void doit(char* allostring)
{
allostring = malloc(6);
memcpy(allostring, "Hello\0", 6);
}
int main()
{
char* strtopass = 0;
doit(strtopass);
free(strtopass);
return 0;
}