I have this function for reading text from files:
uintmax_t ResourcePack::getText(const string& file, char** data)
{
*data = new char[static_cast<size_t>(size) + 1];
fseek(_fileDescriptor, static_cast<long>(begin), SEEK_SET);
fread(*data, static_cast<size_t>(size), 1, _fileDescriptor);
*data[size] = '\0';
}
FILE* _fileDescriptor, uintmax_t size
and uintmax_t begin
are get in other code, not important here, but with correct values.
fseek
and fread
lines work fine.
Actually, I have the file content in *data, but when the last line is executed, I got the access violation.
Why I can write into *data
using fread
, but not using *data[size] = '\0'
?