I need to get a block of text into memory and for that i'd use
text=(char**)realloc(text, no_lines*sizeof(char*));
text[no_lines]=(char*)malloc(max_line_width*sizeof(char));
however when I try
text=(char**)realloc(text, 8*sizeof(char*));
text[0]="test";
it crashes. does anyone know an efficient method of parsing
a block of text, please?
EDIT. Nevermind. solved. Forgot to properly allocate from the very start!
Trying to parse some text ( using C++ )
first up you shouldn't use malloc/calloc/realloc, you should use 'new' and 'delete' in c++:
even better, try irrlicht's string and array classes, they manage all the memory for you and the end result is much cleaner nicer looking code (at the cost of a few cycles)
Code: Select all
c8 **arr = new c8*[size];
delete [] arr;
Code: Select all
array<string<c8> > text;
text.set_used(no_lines);
text[0] = "some text which, ";
text[0] += "unlike a const pointer can be edited later";