完成了第 15 章 套接字和标准I/O

This commit is contained in:
riba2534
2019-01-29 17:52:05 +08:00
parent 94df52b615
commit 21fe034326
8 changed files with 572 additions and 0 deletions

17
ch15/desto.c Normal file
View File

@@ -0,0 +1,17 @@
#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;
}
fp = fdopen(fd, "w"); //返回 写 模式的 FILE 指针
fputs("NetWork C programming \n", fp);
fclose(fp);
return 0;
}