목차
1. 문제정의
2. 문제분석
3. Design
4. 결과화면
5. 결론 및 소감
6. Source
2. 문제분석
3. Design
4. 결과화면
5. 결론 및 소감
6. Source
본문내용
s/types.h>
#include // 시간함수를 사용하기 위한 헤더파일
int main(int argc, char **argv){ // 인자로 복사할 파일과 붙여 넣을 파일명을 입력받는다
FILE *in, *out; // 파일 포인터 in 과 out
char *s;
char str[100];
int c;
double time;
struct timeval start, finish;
struct timezone start_tz, finish_tz;
if(argc !=3){
write(2, "Usage: append src.txt dest.txt\n", 31);
exit(1);
}
in = fopen(argv[1], "r"); // 복사할 파일을 읽기전용으로 연다
out = fopen(argv[2], "w"); // 붙여넣을 파일을 쓰기전용으로 연다
long buff=sizeof(in);
int sel=0;
// 메뉴를 사용자에게 출력하여 보여준다
printf("=========select menu===========\n");
printf("2. one line copy\n");
printf("3. buffer copy\n");
printf("4. exit\n");
printf("===============================\n");
scanf("%d",&sel); // 메뉴번호 입력 받는다.
switch(sel){ // 메뉴번호에 따라 다음과 같이 실행
case 1: // 메뉴번호 1일 경우 1byte 단위로 파일을 복사한다.
printf("Now coping ...\n");
gettimeofday(&start,&start_tz); // 복사 시작 시간
while((c=fgetc(in)) != EOF) {
fputc(c, out);
}
gettimeofday(&finish,&finish_tz); // 복사 완료시간
time=((finish.tv_usec) - (start.tv_usec)); // 복사시간을 time에 넣는다
printf("copy time : %f micro seconds\n", time); // 복사시간 time을 출력
break;
case 2: // 메뉴번호 2일 경우 1line 단위로 파일을 복사한다.
gettimeofday(&start,&start_tz);
printf("Now coping ...\n");
while((s=fgets(str, 100, in))) {
fputs(str, out);
}
gettimeofday(&finish,&finish_tz);
time=((finish.tv_usec) - (start.tv_usec));
printf("copy time : %f micro seconds\n", time);
break;
case 3: // 메뉴번호 3일 경우 버퍼 단위로 파일을 복사한다.
printf("Now coping ...\n");
gettimeofday(&start,&start_tz);
if(fread(out,1,buff,in) != buff){
printf("Copy error !");
exit(3);
}
gettimeofday(&finish,&finish_tz);
time=((finish.tv_usec) - (start.tv_usec));
printf("copy time : %f micro seconds\n", time);
break;
case 4:
printf("bye !");
break;
}
fprintf(out, "copy time : %f micro seconds\n", time); // 파일에 복사시간을 넣는다
fclose(in);
fclose(out);
exit(0);
}
#include
int main(int argc, char **argv){ // 인자로 복사할 파일과 붙여 넣을 파일명을 입력받는다
FILE *in, *out; // 파일 포인터 in 과 out
char *s;
char str[100];
int c;
double time;
struct timeval start, finish;
struct timezone start_tz, finish_tz;
if(argc !=3){
write(2, "Usage: append src.txt dest.txt\n", 31);
exit(1);
}
in = fopen(argv[1], "r"); // 복사할 파일을 읽기전용으로 연다
out = fopen(argv[2], "w"); // 붙여넣을 파일을 쓰기전용으로 연다
long buff=sizeof(in);
int sel=0;
// 메뉴를 사용자에게 출력하여 보여준다
printf("=========select menu===========\n");
printf("2. one line copy\n");
printf("3. buffer copy\n");
printf("4. exit\n");
printf("===============================\n");
scanf("%d",&sel); // 메뉴번호 입력 받는다.
switch(sel){ // 메뉴번호에 따라 다음과 같이 실행
case 1: // 메뉴번호 1일 경우 1byte 단위로 파일을 복사한다.
printf("Now coping ...\n");
gettimeofday(&start,&start_tz); // 복사 시작 시간
while((c=fgetc(in)) != EOF) {
fputc(c, out);
}
gettimeofday(&finish,&finish_tz); // 복사 완료시간
time=((finish.tv_usec) - (start.tv_usec)); // 복사시간을 time에 넣는다
printf("copy time : %f micro seconds\n", time); // 복사시간 time을 출력
break;
case 2: // 메뉴번호 2일 경우 1line 단위로 파일을 복사한다.
gettimeofday(&start,&start_tz);
printf("Now coping ...\n");
while((s=fgets(str, 100, in))) {
fputs(str, out);
}
gettimeofday(&finish,&finish_tz);
time=((finish.tv_usec) - (start.tv_usec));
printf("copy time : %f micro seconds\n", time);
break;
case 3: // 메뉴번호 3일 경우 버퍼 단위로 파일을 복사한다.
printf("Now coping ...\n");
gettimeofday(&start,&start_tz);
if(fread(out,1,buff,in) != buff){
printf("Copy error !");
exit(3);
}
gettimeofday(&finish,&finish_tz);
time=((finish.tv_usec) - (start.tv_usec));
printf("copy time : %f micro seconds\n", time);
break;
case 4:
printf("bye !");
break;
}
fprintf(out, "copy time : %f micro seconds\n", time); // 파일에 복사시간을 넣는다
fclose(in);
fclose(out);
exit(0);
}