dup.c
来自「实用的程序员编程工具」· C语言 代码 · 共 31 行
C
31 行
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <sys\stat.h>
void main(void)
{
int handle;
int duplicate_handle;
char title[] = "Jamsa\'s C/C++ Programmer\'s Bible!";
char section[] = "Files";
if ((handle = open("OUTPUT.TST", O_WRONLY | O_CREAT,
S_IWRITE)) == -1)
printf("Error opening OUTPUT.TST\n");
else
{
if ((duplicate_handle = dup(handle)) == -1)
printf("Error duplicating handle\n");
else
{
write(handle, title, sizeof(title));
close(duplicate_handle); // Flush the buffer
write(handle, section, sizeof(section));
close(handle);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?