C함수 파일로 서식에 맞추어 문자열 출력 dprintf()
서식에 맞추어 파일로 출력합니다.
- 헤더: stdio.h
- 형태: int dprintf( int fd, const char *format, ...)
- 인수: int fd 파일 디스크립터
const char *format 출력할 데이터 서식
... 서식에 맞춘 변수 나열
- 반환: int 출력된 문자 수를 반환하며 오류가 발생하면 음수를 반환합니다.
예제
#include <stdio.h> // puts()
#include <string.h> // strlen()
#include <fcntl.h> // O_WRONLY
#include <unistd.h> // write(), close()
#define BUFF_SIZE 1024
int main()
{
int fd;
if ( 0 < ( fd = open( "./test.txt", O_WRONLY))){
dprintf( fd, "%d %o %s\n", 123, 123, "badayak.com");
dprintf( fd, "%d %o %s\n", 321, 321, "badayak.com");
close( fd);
} else {
printf( "파일 열기에 실패했습니다.\n");
}
return 0;
}
실행 결과
]$ ./a.out
]$ cat text.txt
123 173 badayak.com
321 501 badayak.com
]$