main 함수 전달인자에 관해서
AngelsTears
질문 제목 : 메인함수 전달인자에 관해서예를 들어 메인함수가 int main(int argc, char **argc) 인
copy.exe파일을 cmd 창에서
copy mytext.txt mytext2.txt 라 입력하면
argc에 3이 들어가고
char *a[0]=copy
char *a[1]=mytext.txt
char *a[2]=mytext2.txt 가 들어가는걸로 알고 있는데
argc가 그냥 명령어 개수만 받는줄 알고 아래 파일 복사 소스에서 빼고
copy mytext.txt mytext2.txt 입력하면
char *a[0]=copy
char *a[1]=mytext.txt
char *a[2]=mytext2.txt
일케 되고 똑같이 될줄 알앗더니 에러나네요
말이 길었는데
요지는명령어 개수를 받는argc 값을 꼭 넣어줘야하나봐요? 아니면 지정된 틀인가요?
질문 내용 :
//copy.exe 라 가정
#include stdio.h
int main(char **a)
{
int state,state1;
char str[100];
file *file;
file *file1;
file=fopen(a[1],rt);
file1 = fopen(a[2],wt);
if(file==null || file1==null){
printf(file1 open error \n);
return 1;
}
while(1)
{
fgets(str,sizeof(str),file);
if(feof(file)!=0)
break;
fputs(str,file1);}
state=fclose(file);
state1=fclose(file1);
if(state!=0 || state1!=0){
printf(file close error \n);
return 0;
}
return 0;
}