When i try to read from the file 1.txt (contains only "hello" ) fread returns 6 bytes but there is nothing to print out from buf.
What am i doing wrong?
Code:
#include <wchar.h>
#include <iostream>
using namespace std;
int main()
{
FILE * file = _wfopen(L"1.txt", L"r+b");
int fileSize = 0;
fseek(file, 0, SEEK_END);
fileSize = ftell(file);
rewind(file);
cout << "Filesize: " << fileSize << " bytes." << endl;
wchar_t * buf = (wchar_t *)calloc(260,sizeof(wchar_t));
size_t result = fread(buf, sizeof(wchar_t), fileSize, file);
printf( "%ls\n", buf );
cout << "fread returns: " << result << endl;
free(buf);fclose(file);
}