Thanks Narue, I understand now
please, can you check if this is a correct way of reading file:
first, file is open for both writing and reading
hFile = CreateFile("MYFILE.TXT", // open MYFILE.TXT
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ, // share for reading
NULL, // no security
OPEN_ALWAYS, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr
second I want to read contents of a file and display it on screen (I know that file contents are sentences (strings) like
"This is first sentence"
"This is second sentence"
so this is code for reading:
while(ReadFile(hFile, buf, sizeof buf, &dw_bytes_read, NULL) && dw_bytes_read != 0)
{
WriteFile(hStdOut, buf, dw_bytes_read, &dw_bytes_written, NULL);
}
I had one nasty problem, At first I tried this:
while(ReadFile(hFile, buf, sizeof buf, &dw_bytes_read, NULL)){...
but program ended up in an infinite loop (not like fwrite in C) and that way with dw_bytes_read it appears to work fine.
Can you suggest me other, better, way of doing this if this is not OK
Thanks