I need to use reaalloc to extend the memory when it goes out of bounds but I am not getting a correct output.
this is how i am trying to realloc
Code:
if(strlen(theString) - strlen(searchFor) + strlen(replace) >= size -1)
{
size += 80;
// theString = strcpy(theString,theString);
theString = (char*)realloc(theString,size);
printf("realloc worked! size should be more");
}
my declarations:
stringHolder = theString, searchString = searchFor, substituteString= replace.
Code:
size = 6;
stringHolder = (char*) calloc(size,sizeof(char));//, sizeof(char));
searchString = (char*) calloc(10, sizeof(char));//, sizeof(char));
substituteString = (char*) calloc(10,sizeof(char));//, sizeof(char));
how i am printing it:
Code:
printf("\n%s", theString);
printf("\n%d", strlen(theString));
output:
Please enter a string that is less then 80 characters:
hello
Please enter a substring to search:
e
Enter a string less then 10 characters to replace
aaa
realloc worked! size should be more
`☼j
3
Process returned 0 (0x0) execution time : 6.906 s
Press any key to continue.
output should be:
haaallo
7
Anyone advice or help?