본문 바로가기

Programming/Windows&C#

[Windows/WinAPI] 윈도우 시스탬 프로그래밍 실습 01

728x90
반응형

//첫 수업 간단한 파일 복사 예제.


#include <stdio.h>

#include <errno.h>


#define BUF_SIZE 256


int main(int argc, char *argv[])

{

FILE *inFile, *outFile ;


char rec[BUF_SIZE];

size_t byteIn, byteOut;


if(argc != 3)

{

fprintf(stderr, "Usage : copyC file1 file2\n");

return 1;

}


inFile = fopen(argv[1],"rb");

outFile = fopen(argv[2],"wb");

if(inFile == NULL)

{

perror(argv[1]);

return 1;

}

if(outFile==NULL)

{

perror(argv[2]);

return 1;

}


while((byteIn = fread(rec,1,BUF_SIZE, inFile))>0)

{

byteOut = fwrite(rec,1,byteIn,outFile);

if(byteOut != byteIn)

{

perror("Fatal write error");

fclose(inFile);

fclose(outFile);

return 4;

}

}


fclose(inFile);

fclose(outFile);


return ;

}

copy.c


반응형