i have this code that basically read from file and create new file and write the contend from the source to the destination file . it reads to the buffer and creates the file ,
but fwrite
dost write the content to the new created file i have no idea why ..
here is the code . ( i have to use only this with _sopen , its part of legacy code)
Code:
std::string szSource = "H:\\cpp\\test1.txt";
FILE* pfFile;
int iFileId = _sopen(szSource.c_str(),_O_RDONLY, _SH_DENYNO, _S_IREAD);
if (iFileId >= 0) 
 pfFile = fdopen(iFileId, "r");

//read file content to buffer 
char * buffer;
size_t result;
long lSize;
// obtain file size:
fseek (pfFile , 0 , SEEK_END);
lSize = ftell (pfFile);
fseek(pfFile, 0, SEEK_SET);

 buffer = (char*)malloc(lSize);
// also i did :
//buffer = (char*) malloc (sizeof(char)*lSize); <--same not working

if (buffer == NULL)
{

   return false;
}

// copy the file into the buffer:
result = fread (buffer,lSize,1,pfFile);   
std::string szdes = "H:\\cpp\\test_des.txt";
FILE* pDesfFile;
int iFileId2 = _sopen(szdes.c_str(),_O_CREAT,_SH_DENYNO,_S_IREAD | _S_IWRITE);
if (iFileId2 >= 0) 
 pDesfFile = fdopen(iFileId2, "w+");

size_t f = fwrite (buffer , 1, sizeof(buffer),pDesfFile ); //<-- the f returns me 4
// also did:
//size_t f = fwrite (buffer , 1, lSize ,pDesfFile ); // bu dosnt work
fclose (pDesfFile);