S
squid
I am trying to pass a pointer to a function and in the function
allocate some memory for it using malloc and then using it in the
calling function. If I return the pointer in the function return
value and assign it to a pointer variable when I call the function it
works. But when I try to use the pointer I sent as a parameter it
says the pointer variable is undefined and I am unable to access the
allocated memory.
#include <stdio.h>
#include <stdlib.h>
char * getbuff(char *);
void main(void)
{
char *a, *b;
b = getbuff(a*);
return;
}
char * getbuff(char * p)
{
char * buff;
buff = (char *) malloc(sizeof(char) * 8);
p = buff;
return buff;
}
allocate some memory for it using malloc and then using it in the
calling function. If I return the pointer in the function return
value and assign it to a pointer variable when I call the function it
works. But when I try to use the pointer I sent as a parameter it
says the pointer variable is undefined and I am unable to access the
allocated memory.
#include <stdio.h>
#include <stdlib.h>
char * getbuff(char *);
void main(void)
{
char *a, *b;
b = getbuff(a*);
return;
}
char * getbuff(char * p)
{
char * buff;
buff = (char *) malloc(sizeof(char) * 8);
p = buff;
return buff;
}