DUP.C
上传用户:qq5388545
上传日期:2022-07-04
资源大小:29849k
文件大小:1k
- #include <stdio.h>
- #include <fcntl.h>
- #include <io.h>
- #include <sysstat.h>
- void main(void)
- {
- int handle;
- int duplicate_handle;
- char title[] = "Jamsa's 1001 C/C++ Tips!";
- char section[] = "Files";
- if ((handle = open("OUTPUT.TST", O_WRONLY | O_CREAT,
- S_IWRITE)) == -1)
- printf("Error opening OUTPUT.TSTn");
- else
- {
- if ((duplicate_handle = dup(handle)) == -1)
- printf("Error duplicating handlen");
- else
- {
- write(handle, title, sizeof(title));
- close(duplicate_handle); // Flush the buffer
- write(handle, section, sizeof(section));
- close(handle);
- }
- }
- }