Hi,
I'm trying to write a string to a file using win32 function "WriteFile".
The file is written with partial data (4 x'c' insted of 10).
What am i doing wrong?
Thanks,
Alonex
My code:
========
const char ostream[] = "c:\\test.txt";
hFile = CreateFile(ostream,GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORM AL,NULL);
for (int i=0;i<10;i++)
{
ip[index++]='c';
}
char *ipR=NULL;
ipPtr = (char *) malloc(index);
int j;
for (j=0;j<index;j++)
{
ipPtr[j]=ip[j];
}
ipR[index+1]='\0';
WriteFile(hFile,ipPtr,(DWORD)(sizeof(ipPtr)),&wmWritten,NULL);
CloseHandle(hFile);
========================
I'm trying to write a string to a file using win32 function "WriteFile".
The file is written with partial data (4 x'c' insted of 10).
What am i doing wrong?
Thanks,
Alonex
My code:
========
const char ostream[] = "c:\\test.txt";
hFile = CreateFile(ostream,GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORM AL,NULL);
for (int i=0;i<10;i++)
{
ip[index++]='c';
}
char *ipR=NULL;
ipPtr = (char *) malloc(index);
int j;
for (j=0;j<index;j++)
{
ipPtr[j]=ip[j];
}
ipR[index+1]='\0';
WriteFile(hFile,ipPtr,(DWORD)(sizeof(ipPtr)),&wmWritten,NULL);
CloseHandle(hFile);
========================