Can't write data into variable

So, you KNOW how big the file is. Why do you need to do dynamic memory allocation, then? Just allocate a char array big enough to hold the complete file, and fill it in one call to read().