If you have a pointer outside a function, and you pass it to a function, that function can only change the value of what is already being pointed at.
If you have a pointer outside a function, and inside the function you want to make it point to something else, then you instead need to pass a pointer to that pointer so you can make that pointer point to something else.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void foo( char **bar )
{
*bar = malloc( strlen("World!" ) + 1 );
strcpy( *bar, "World!" );
}
int main( void )
{
char array[] = "Hello ";
char *s;
s = array; /* point at the array */
printf("%s", s );
foo( &s ); /* s will now point to newly allocated memory */
printf("%s", s );
free( s );
return 0;
}
Is that basicly what you're trying to do?
Quzah.