I am trying to allocate string of unknown length. I have made this program to do so, it works fine, but when I try valgrind it always shows 1 error the "Conditional jump or move depends on uninitialised value(s)" The program looks something like this
char *text = NULL;
int i = 0, error = 0;
text = (*char) malloc(sizeof(char));
while(1){
error = scanf("%c", &text[i]);
if(error == EOF)
break;
i++;
text = (*char) realloc(text, sizeof(char) * (i + 1));
}
printf("%s", text);
free(text);
I have tried using
scanf("%ms", &text);
but this stops, when a new line character appears, which is a problem in my task. Any suggestions ?