1 ... 2 3 4 5 6 7 8 9 10 ... 12
#include <windows.h>
#include <stdio.h>
#define BUF_SIZE 256

int main(int argc, char **argv)
{
  HANDLE hIn, hOut;
  DWORD dwIn, dwOut;
  char buffer[BUF_SIZE];
 
  if( argc != 3 )
  {
    printf("Useage : %s file1 file2", argv[0]);
    return 1;
  }
 
  hIn = CreateFile( argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
  if( hIn == INVALID_HANDLE_VALUE )
  {
    printf("Cannot open input file. Error code = %x\n", GetLastError() );
    return 2;
  }
 
  hOut = CreateFile( argv[2], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  if( hOut == INVALID_HANDLE_VALUE )
  {
    printf("Cannot write output file. Error code = %x\n", GetLastError() );
    return 3;
  }
 
  while( ReadFile(hIn, buffer, BUF_SIZE, &dwIn, NULL) && (dwIn > 0) )
  {
    WriteFile(hOut, buffer, BUF_SIZE, &dwOut, NULL);
   
    if( dwIn != dwOut )
    {
      printf("Fatal Write Error!, Code = %x", GetLastError() );
      return 4;
    }
  } // while
 
  CloseHandle(hIn);
  CloseHandle(hOut);
 
  return 0;
}

 
2006/05/14 00:02 2006/05/14 00:02

덧글을 달아 주세요


1 ... 2 3 4 5 6 7 8 9 10 ... 12