I have a function which outputs a really long string in a box of defined size. The problem is, after a few lines, I get an error saying that HEAP CORRUPTION has occured and I wrote to a memory beyond the allocated limit. Now, I'm only writing to console and not to memory so this has me puzzled to my wits end. Can some one please take a look and tell me whats wrong?
int TextField::edit(){
int x = console_Box(frow - 1, fcol - 1, len + 2, txtHeight + 2, txtEdge, txtTop_btm, txtLs_rs); //Function to make the box
int index = 0, i = 0, exitCode = 0, lenSent = 0;
char * line = new char[fslen + 10];
for(i = 0; i < txtHeight; i++){
//the original string of data is 'fstr'
//getline gets a single line, of length 'len'. the start position is 'i'
//and 'lenSent' is the length of the string already sent.
strcpy(line, getLine(fstr, len, i, lenSent)); //I get an error here,
//which makes no sense as getline will always return a string
// 10 characters shorter than line.
console_Move(frow + i, fcol);
console_PutS(line);
lenSent += strlen(line);
}
console_Move(frow, fcol);
return exitCode;
}