background image

main()
{
char s[80];
fputs(fgets(s,80,stdin),stdout);
}

 

执行 this is a test /*输入*/
this is a test /*输出*/

 

 
fileno

 

(返回文件流所使用的文件描述词)

 

相关函数 open,fopen 

 

表头文件 #include<stdio.h> 

 

定义函数 int fileno(FILE * stream); 

 

函数说明 fileno()用来取得参数 stream

 

指定的文件流所使用的文件描述词。

 

返回值 返回文件描述词。

 

范例
#include<stdio.h>
main()
{
FILE * fp;
int fd;
fp=fopen(“/etc/passwd”,”r”);
fd=fileno(fp);
printf(“fd=%d\n”,fd);
fclose(fp);
}

 

执行 fd=3

 

 
fopen

 

(打开文件)

 

相关函数 open,fclose 

 

表头文件 #include<stdio.h> 

 

定义函数 FILE * fopen(const char * path,const char * mode); 

 

函数说明 参数 path 字符串包含欲打开的文件路径及文件名,参数 mode 字符串则代表着
流形态。
mode 有下列几种形态字符串:
r 打开只读文件,该文件必须存在。
r+ 打开可读写的文件,该文件必须存在。
w 打开只写文件,若文件存在则文件长度清为 0,即该文件内容会消失。若文件不存在则
建立该文件。
w+ 打开可读写文件,若文件存在则文件长度清为零,即该文件内容会消失。若文件不存
在则建立该文件。