C lang을 사용하여 한 파일에서 다른 파일로 유닉스 텍스트를 복사하려고합니다. 아래는 내 코드의 일부입니다. 내가 프로그램을 실행할 때 분할 오류 오류가 발생했습니다.유닉스에서 파일 복사 중 세그먼트 오류
감사 어떤 도움 ..
#include<fcntl.h>
#include<unistd.h>
#include<stdio.h>
int main (int argc, char *argv[])
{
char buffer[BUFFSIZE];
int infile;
int outfile;
int n;
size_t size;
printf("Enter the Source file name: \n");
scanf("%s",&argv[1]);
printf("Enter the Destination file name : \n");
scanf("%s", &argv[2]);
if((infile = open(argv[1], O_RDONLY,0)) < 0)
{
perror("Source file does not exist");
return -1;
}
if((outfile=open(argv[2],O_WRONLY,0644))>0)
{
printf("Target/Destination File Exists:\n \n ");
//printf("Target Fiel Exists , Do you wish to Overwrite or Appened Data to it: \n \n 1=Yes(Overwrite),\n 0=No(Append):\n");
scanf("%d",&n);
if(n==1)
{
if((outfile=open(argv[2],O_WRONLY|O_CREAT |O_EXCL, 0644)>=0))
{
printf("File is Being opened in Overwrite Mode: \n \n");//File is overwrited
}
}
}
}
모든 경고와 디버그 정보로 컴파일 했습니까? 'gcc -Wall -g'? 디버거'gdb'를 사용 했습니까? –