#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char * str = "Hello World\n";
char * str2 = "Goodbye World\n";
char **p, **start, **tmp;
char * str3;
int i =1, j =0;
int main(int argv, char * argc[]){
if((p = malloc(sizeof(char **)))== NULL){
printf("malloc error\n");
return 0;
}
start = p;
while(i){
str = "Hello World\n";
printf ("str==>%s ", str);
printf ("str ===>%zd \n", strlen(str) );
str = (char *) malloc( ( strlen(str2) + 1) );
strcpy(str,str2);
printf ("str2==> %s", str);
printf ("str2==>%zd \n", strlen(str) );
str3 = (char *) malloc( ( (2* strlen(str2)) + 1) );
strcpy(str3,str2);
strcat(str3,str2);
printf ("str3==> %s", str3);
printf ("str3==> %zd\n", strlen(str3) );
if((*p = (char *) malloc( ( strlen(str) + 1) ))==NULL){
printf("Malloc Failed\n");
return 0;
}
strcpy( *p, str);
printf ("*p ==> %sindex==> %d\n", *p, i);
p = start;
for(j=0; j < i; j++){
printf("Whole Block P index ==> %s", *p);
p++;
}
if((tmp = realloc(start, (sizeof(char**) * i))) == NULL){
printf("Error in Reaalloc ==> %zu", (sizeof(char**) * i));
return 0;
}
start = tmp;
for(j=0; j < i; j++){
printf("Whole Block ==> %s", *(start + j));
}
i++;
printf("Back to Top \n\n");
}
return 0;
}