char *dumpTB (TB tb){
char* text = malloc(sizeof(char));
int i = 0; //
int x = 0; //string index
tNode* curr = tb->head;
while(curr != NULL){
while(curr->line[x] != '\n'){
printf("%d", i);
text[i] = curr->line[x];
printf("%c\n", text[i]);
text = realloc(text, i+1);
i++;
x++;
}
text[i] = '\n';
printf("%c", text[i]);
text = realloc(text, i+1);
i++;
x = 0;
curr = curr->next;
}
return text;
}
So I manage to print out the first 12 letters of my string using the print statements but for some reason it gives me a seg fault shortly after printing the 12th letter 'l', and based on the print statements it seems to occur around the realloc...can anyone tell me what I did wrong?
int i = 1; //
int x = 0; //string index
tNode* curr = tb->head;
while(curr != NULL){
while(curr->line[x] != '\n'){
printf("%d", i-1);
text[i-1] = curr->line[x];
printf("%c\n", text[i-1]);
text = realloc(text, i+1);
i++;
x++;
}
printf("%d\n", i-1);
text[i-1] = '\n';
printf("%c", text[i-1]);
text = realloc(text, i+1);
i++;
x = 0;
curr = curr->next;
//printf("%c\n", curr->line[0]);
}
I tried fixed the index errors, a really long looking sysmalloc assertion thing which aborts the program.