Files
TCP-IP-NetworkNote/ch15/todes.c
2024-09-25 21:36:31 +08:00

21 lines
474 B
C

#include <stdio.h>
#include <fcntl.h>
int main()
{
FILE *fp;
int fd = open("data.dat", O_WRONLY | O_CREAT | O_TRUNC);
if (fd == -1)
{
fputs("file open error",stdout);
return -1;
}
printf("First file descriptor : %d \n", fd);
fp = fdopen(fd, "w"); //转成 file 指针
fputs("TCP/IP SOCKET PROGRAMMING \n", fp);
printf("Second file descriptor: %d \n", fileno(fp)); //转回文件描述符
fclose(fp);
return 0;
}