>> Delete No. 50211 article
No. open()과 write()의 사용법에 관하여 질문

등록 2002-06-01 13:20:00 By localhost     조회 3
이름 앗~싸    

안녕하세요...
제가 아래와 같이 프로그래밍을 했는데요...
인수가 4개일 때 두번째가 -i 이면 3번 파일을 불러서 4번 파일을 생성하거나
만약 그 파일이 있다면 밑에 붙여넣기를 하는 건데요...
근데 이상하게 잘 안되네요...
뭐가 잘못 됐는지 좀 알려주세요...
인수가 2개일 때는 표준입력을 받아서 파일로 저장하는 건데 그건 잘 되거든요
그리고 dup()는 어떤 때 사용하는지도 아시면 알려주시면 감사하겠습니다...
  #include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
 #define BUFFSIZE 8192
 int main(int argc, char *argv<>)
{
	int inhandle;
	int outhandle;
	int bytes;
	char buf[BUFFSIZE];
 	if (argc = 2)
	{
		bytes = read(STDIN_FILENO, buf, BUFFSIZE);
		outhandle = open(argv[1], O_WRONLY | O_CREAT | O_APPEND,
			S_IRWXU);
 	}
 	if (argc = 4)
	{
		if (argv[1] == "-i")
		{
			inhandle = open(argv[2], O_RDONLY);
			bytes = read(inhandle, buf, BUFFSIZE);
			outhandle = open(argv[3], O_WRONLY | O_CREAT |
					O_APPEND, S_IRWXU);
		}
 	}
 	write(outhandle, buf, bytes);
	close(inhandle);
	close(outhandle);
 	exit (1);
}--'Love' is my life!
[관리자] 패스워드를 입력 하십시오. 답장이 존재하면 함께 삭제됩니다.[ 목록 | 이전 ]
패스워드:    

Copyleft 1999-2026 by JSBoard Open Project
Theme Designed by IDOO All right reserved