modify pointer to a string/character constant.
in c programming language.
I have 1 question
1)
Code:
#include <stdio.h>
#include <string.h>
int main()
{
char *x;
char t[10]= "telephone";
x=(char *)malloc( sizeof(char) *6 );
x=t;
printf("%s\n",x);
free(x);
/* x[0]='t' will probably give segementation fault.. */
printf("%s\n",x);
return 0;
}
the output is:
telephone
telephone
even though I had free(x);
How do I properly free this, supposing I want the char *x to point to something else.
For example say I have the string "telephone" and want it to be "zelephone"