void replace(char *str) {
unsigned int len = 0;
unsigned int no_of_spaces = 0;
while (*str) {
if ((char)*str == SPACE)
no_of_spaces++;
str++;
len++;
}
unsigned int new_len = len + 2 * no_of_spaces;
str = (char*) realloc(str, new_len * sizeof(char));
str[new_len] = '\0';
}
I use function like replace("random string");
.
Here I am trying to increase the size of the string so that spaces can be replaced with another string. For this I need to count the no of spaces and also get the length of the original string. I have been able to do that.
For resizing I am using realloc
but when I run it, it gives Aborted (core dumped)
?