Well, you need to allocate a buffer big enough for this to work. The following code doesn't work. Try it:
Code:
char *test = "testing";
char *test2 = (char*)realloc( test, 30 ); // You should get an error here
The test variable is effectively a char[8] in this case, which won't allow reallocation.
So, to get what you want you probably want something:
Code:
char *test = (char*)malloc( 5 );
char *test2;
strcpy( test, "test" );
printf( "%s (%d)\n", test, strlen(test) );
// The would result in an error if uncommented: strcat( test, "test" );
test2 = (char*)realloc( test, 20 );
strcat( test2, "test" );
printf( "%s (%d)\n", test, strlen(test) );
you have sufficient memory for your allocation.