Dynamic Memory Allocation - Example
{ char *str, *new_str, *str1;
str = (char*) malloc(LNG2);
while (printf(“Enter 6-char string\n”), gets(str)) { printf(“ %s ==>> “,str);
string_manipulation(str,tolower);
} new_str = (char *)realloc(str,LNG2+LNG1); printf(“new_str=%s\n”,new_str);
printf(“ str=%s\n”, str);
string_manipulation(str,toupper);
printf(“new_str=%s\n”,new_str);
printf(“ str=%s\n”, str);
str1 = (char *) malloc(LNG2);
printf(“ str1=%s\n”, str1); string_manipulation(str1,tolower); printf(“ str1=%s\n”, str1);
free(str1); free(new_str);