-
April 12th, 2010, 03:56 AM
#1
Help with ReadFile()
Hello, I wrote this code. All it does is read Readme.txt and displays its content. How could I modify my code so that it could read Readme.txt from a Nth byte position I specify?
For example, the content of the TXT File is: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
I want my function to read the file from (for example) the F until M and store it in a variable.
I need my function to read only 8 byte of a file from Nth position. Is it possible?? Thanks!
Code:
int main(int argc, char* argv[])
{
HANDLE hFile;
hFile = CreateFile("H:\\readme.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,0,0);
if (hFile == INVALID_HANDLE_VALUE) {
printf("File was not found\n");
} else {
DWORD dwFileSize;
dwFileSize = GetFileSize(hFile, NULL);
if(dwFileSize != 0xFFFFFF) {
LPSTR FileContent;
FileContent = (LPSTR) GlobalAlloc(GPTR, dwFileSize +1);
if (FileContent != NULL)
{
DWORD dwRead;
if(ReadFile(hFile,FileContent, dwFileSize, &dwRead,NULL)) {
FileContent[dwFileSize] = 0; // NULL TERMINATOR
printf(FileContent);
}
GlobalFree(FileContent);
}
}
CloseHandle(hFile);
}
return 0;
}
-
April 12th, 2010, 04:01 AM
#2
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|