// 파일 두개를 합쳐서 하나의 파일에 복사
#include <Windows.h>
#include <stdio.h>
#include <tchar.h>
#include <locale.h>
int _tmain (int argc, LPCTSTR argv[])
{
HANDLE hIn1, hIn2 , hOut;
DWORD nIn1, nIn2, nOut;
TCHAR buffer[256];
_tsetlocale(LC_ALL , _T("korean"));
if(argc != 4)
{
_tprintf(_T("error1"));
return 1;
}
hIn1 = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hIn1 == INVALID_HANDLE_VALUE)
{
_tprintf(_T("error2"));
CloseHandle(hIn1);
return 2;
}
hIn2 = CreateFile(argv[2], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hIn2 == INVALID_HANDLE_VALUE)
{
_tprintf(_T("error3"));
CloseHandle(hIn1);
CloseHandle(hIn2);
return 2;
}
hOut = CreateFile(argv[3], GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hOut == INVALID_HANDLE_VALUE)
{
_tprintf(_T("error4"));
CloseHandle(hIn1);
CloseHandle(hIn2);
CloseHandle(hOut);
return 3;
}
while(ReadFile(hIn1,buffer, 256, &nIn1,NULL)&& nIn1 >0)
{
WriteFile(hOut, buffer, nIn1, &nOut,NULL);
if(nIn1 != nOut)
{
_tprintf(_T("error5"));
CloseHandle(hIn1);
CloseHandle(hOut);
return 4;
}
}
while(ReadFile(hIn2,buffer, 256, &nIn2,NULL)&& nIn2 >0)
{
WriteFile(hOut, buffer, nIn2, &nOut,NULL);
if(nIn2 != nOut)
{
_tprintf(_T("error6"));
CloseHandle(hIn1);
CloseHandle(hIn2);
CloseHandle(hOut);
return 5;
}
}
_tprintf(_T("굿\n"));
CloseHandle(hIn1);
CloseHandle(hIn2);
CloseHandle(hOut);
return 6;
}
'개발' 카테고리의 다른 글
[Android] View (0) | 2013.09.29 |
---|---|
[Windows/WinAPI] FindFirstFile , FileTimeToSustemTime, FindNextFile (실습3) (0) | 2013.09.27 |
[Windows/WinAPI] 윈도우 시스탬 프로그래밍 실습 01 (0) | 2013.09.06 |
[C언어] 주소록 linked list + file I/O (0) | 2013.07.31 |
[C언어] 간단한 주소록 만들기를 링크드리스트로 구현 (0) | 2013.07.31 |