I read a text file with a content like this "sasdfsdf" with the following code:
char* o = new char[size];
c = 0;
for (i = 0; i < n; i++)
{
fseek(pFile, i, SEEK_SET);
b = fgetc(pFile);
if (b == '\r') {
o[c] = b;
c++;
o[c] = '\n';
}
else {
o[c] = b;
}
c++;
}
fclose(pFile);
SetWindowTextA(TextBox1.hWnd, (n > 0) ? o : NULL);
delete[] o;
First I would like to know if this code is clean. I assume it is not because I am new to C/Cpp and have sometimes some problems with understanding the allocating-stuff. I would like to use the C-style (FILE*, fopen, fseek, fgetc) to get the content of the file. The problem is that the char* o is always added something. I have an example: instead of "sasdfsdf" (text file content) it writes "sasdfsdf¨‰»3" into the edit control. I found out that the "¨‰»3" is added when the for-loop-scope is left. I assume it is something like a memory leak. I have no other idea where this characters should come from.