Consider I have a string called "bhuvanesh"
, to store that string , Initially allocate the memory using malloc()
char *ptr=(char *)malloc(sizeof("bhuvanesh"));
sprintf(ptr,"bhuvanesh");
Then I want to add the string with the previously stored memory , the string is "waran"
. so I am using realloc()
ptr=(char *)realloc(ptr,15);
The function realloc()
will return the starting address, so concatenate the string I can use strcat()
function
strcat(ptr,"waran");
or else I can do like that
char *p=ptr;
p=p+sizeof("bhuvanesh");
sprintf(p,"waran\n");
Is there is any way to do this ?