I seen that there are many topics about it but I couldnt see(or understand) something that will be helpful for me. I am trying to create a function that get int max_length and then generate a random words until its generate max_length words. Then I want to print it. This is just an example when max_length is 20 and the new_word is always 'abc', but from some reason after max_length = 7 its keep giving me this error 'realloc invalid next size'..
int num_of_words = 0;
int max_length = 20;
char *new_word = "abc";
char *twit = malloc (strlen (new_word)+1);
while (num_of_words < max_length){
twit = realloc (twit, strlen(new_word)+5);
strcat (twit, new_word);
strcat (twit, " ");
num_of_words++;
}
printf("%s", twit);
return EXIT_SUCCESS;
}