I have a little problem that i can't figure out.
I am trying to read a file into a buffer,
My problem is that sometimes it adds a random character at the end of the text. (sometimes ? and abs etc.). So i wonder why that is happening. I haven't found any solution yet. The problem happens randomly, not every time i read the file.
static char text[1024 * 16];
std::ifstream File(FilePath, std::ios::in | std::ios::out | std::ios::binary | std::ios::ate);
std::streamsize Size = File.tellg();
File.seekg(0, std::ios::beg);
char *string = new char[Size + 1];
if (File.is_open())
{
File.read(string, Size);
memset(text, 0, sizeof(text));
snprintf(text, sizeof(text), "%s", string);
}
File.close();
delete[] string;