시스템프로그래밍 Lecture8. cmdline-arg
- 최초 등록일
- 2015.01.04
- 최종 저작일
- 2013.05
- 9페이지/ 한컴오피스
- 가격 1,000원
소개글
수정할 곳 없는 정말 완벽한 보고서입니다.
보고서 쓰시는데 도움이 되었으면 좋겠습니다.
목차
Lecture8 : cmdline-arg
1) Try ex1.c and mycat.c.
2) Modify mycat such that it can display two files$ mycat f1 f2
2-1) Implement mycpmycp f1 f2will copy file f1 into f2.
3) Modify mycat such that it can handle any number of files.
5) Modify mycat to handle various options. The second argument is either a file or an option. If it is a file, just display the contents. If it is an option (starting with ‘-‘), perform the following corresponding actions.
본문내용
먼저 vi인 텍스트에디터를 이용하여 다음과 같이 ex8_1.c를 작성한다.
소스파일을 컴파일하고 실행하면 다음과 같이 출력됨을 볼 수 있다. 즉 공백을 기준으로 string을 받아 출력함을 확인할 수 있다.
vi인 텍스트에디터를 이용하여 다음과 같이 mycat.c를 작성한다.
<중 략>
먼저 vi인 텍스트에디터를 이용하여 다음과 같이 mycp.c를 작성한다. 파일 x1을 하나 더 open하여 x에서 읽은 내용을 x1에 write한다.
소스파일을 컴파일하고 실행하면 다음과 같이 출력됨을 볼 수 있다. 즉 f1의 내용이 f3에 copy됨을 확인할 수 있다.
3) Modify mycat such that it can handle any number of files.
$ mycat f1
will print the contents of f1.
$ mycat f1 f2 f3
Will print the contents of f1, f2, and f3.
vi인 텍스트에디터를 이용하여 다음과 같이 mycat.c를 수정한다. 즉 입력받은 파일의 수만큼 출력하도록 코드를 작성한다.
<중 략>
소스파일을 컴파일하고 실행하면 다음과 같이 출력됨을 볼 수 있다.
$ mycat -o f1out f1
will copy f1 into f1out. (same effect as “cat f1 > f1out”)
$ mycat –x f1
will print the contents of f1 in hexadecimal numbers in the screen. (similar effect as “xxd f1”)
$ mycat –p /etc/passwd
will show the contents of /etc/passwd more user-friendly as follows:
account: root
password: x
uid: 0
gid: 0
............
You may need fopen, fgets, strtok() for this program.
참고 자료
없음