Hello All,
Its hard to explain but here it goes:
char &free_malloc(char* object_copy){
Here ------------------------------------------------------------------
object_copy is parametre were the contents of the malloc object in main
driver module is copied.
Which would mean that if I free the object_copy it should not effect
the malloc pointer in the main module.
Here ------------------------------------------------------------------
char *ret_buf ;
char dummy;
char *source;
dummy = 0;
source = object_copy;
if(object_copy !=0 || object !=NULL)
free(object_copy);
/* determine how pointer length is needed */
do{
dummy = *source;
source++;
ret_buf++;
}while(dummy!='\0' || dummy!=0);
//insert here the end of the string
ret_buf++;
ret_buf = dummy;
//clean up all of the contents here //
ret_buf = strcpy( ret_buf,"");
//Does the following code work
ret_buf = &(*object_copy);
ret_buf = strcpy( ret_buf,object_copy);
return ret_buf;
}
int main(int argc,char *argv[]){
char *malloc = malloc(6);
char *buffer = 0;
buffer = free_malloc(malloc);
free(malloc);
printf("Display Buffer = %s\n", buffer);
return 0;
}
Basically what I am trying to do is copy the RAM object contents to the
local stack.
I am trying to accomplish this by using the above function that I would
want to use.
This way I can forget calling malloc/ free combination.
I have no idea how can I copy the contents of mallocated RAM object to
the local variable and return new local variable as a returned object.
Can somebody help?