c언어 파일입출력 관련 질문입니다.

Fish2222의 이미지

비주얼스튜디오2017로 c언어를 배우는 중인데요. 콘솔화면에서 C:\projectname a.txt b.txt 라고 입력하고 엔터키를 치면 a.txt 파일의 내용을 복사해서 b.txt라는 파일을 만들고 싶습니다.

파일복사는 알겠는데 콘솔창에 저렇게 치면 복사가 되게하는 방법은 쉽지가 않더군요..
도움 주시면 감사하겠습니다.

세벌의 이미지

구글에서
The C programming language
찾아보세요. pdf 파일 어딘가에 파일 복사하는 프로그램이 예제로 있을 겁니다.

익명 사용자의 이미지

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
 
C:\Users\user-pc>copy con projectname.bat
@echo off
copy %1 %2
^Z
        1개 파일이 복사되었습니다.
 
C:\Users\user-pc>copy con 1.txt
123
^Z
        1개 파일이 복사되었습니다.
 
C:\Users\user-pc>projectname 1.txt 2.txt
        1개 파일이 복사되었습니다.
 
C:\Users\user-pc>type 1.txt
123
 
C:\Users\user-pc>type 2.txt
123

#include <stdlib.h>
 
int main(int argc, char **argv) {
    char cmd[1024];
    snprintf(cmd, 1024, "copy %s %s", argv[1], argv[2]);
    system(cmd);
}

아 저렇게 해결할 수는 있지만 문제를 낸 사람이 저렇게 풀 것을 의도하지는 않았을 거라고 생각합니다.