#include <stdlib.h>
#include <iostream.h>
#include <string.h>
#include<conio.h>
void main()
{
clrscr();
char *p;
p = (char*)malloc(17);
if(!p)
{
cout<<"Allocation Error\n";
exit(1);
}
strcpy(p, "This is 16 chars");
p = (char*)realloc(p, 18);
if(!p)
{
cout<<"Allocation Error\n";
exit(1);
}
strcat(p, ".");
cout<<p;
free(p);
getch();
}
Output:
This is 16 chars