📄 close.c
字号:
/****************************************************************相关的头文件:#include<unistd.h>函数表达式 :int close(int fd);参数说明 :close函数的参数fd表示需要关闭的文件的文件描述符。返回值说明 :成功关闭文件则返回0,失败则返回-1。函数功能详解:略****************************************************************/#include<stdio.h>#include<stdlib.h>#include<unistd.h> /*close函数所在头文件*/#include<fcntl.h> /*open函数所在头文件*/int main(void){ int fd; /*文件描述符,成功则返回0,失败则返回-1*/ fd=open("test.txt",O_RDWR|O_CREAT,0700); /*打开一个文件*/ if(fd == -1) { perror("fail to open"); /*出错则输出出错信息*/ exit(1); } else printf("open OK\n"); /*成功打开文件则输出提示信息*/ if(close(fd)==-1) /*关闭打开的文件*/ { perror("fail to close"); /*出错则输出信息*/ exit(1); } else printf("close OK\n"); /*成功关闭文件则输出提示信息*/ return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -