home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Win32 Under the API
/
ProgrammingWin32UnderTheApiPatVillani.iso
/
Chapter5
/
5-3
/
SimpleIO.c
Wrap
C/C++ Source or Header
|
2000-07-14
|
573b
|
33 lines
#include <windows.h>
#define CTL_Z 0x1a
INT main(INT argc, BYTE *argv[])
{
HANDLE hFile;
DWORD nRead;
BYTE c;
if(argc != 2)
return FALSE;
if((hFile = CreateFile((LPCTSTR)argv[1], GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)) == INVALID_HANDLE_VALUE)
{
printf("Cannot find file \"%s\"\n", argv[1]);
return 1;
}
while(ReadFile(hFile, (LPVOID)&c, (DWORD)1, &nRead, 0) && (nRead == 1))
{
if(c == CTL_Z)
break;
printf("%c", c);
}
CloseHandle(hFile);
printf("\n");
return 0;
}