C语言文件操作函数大全(超详细)

2020-01-06 20:18:48王冬梅

返回值 gets()若成功则返回s指针,返回NULL则表示有错误发生。
范例 
复制代码
#include<stdio.h>
main()
{
char s[80];
fputs(fgets(s,80,stdin),stdout);
}
执行 this is a test /*输入*/
this is a test /*输出*/
10.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
12.fputc(将一指定字符写入文件流中)
相关函数 fopen,fwrite,fscanf,putc
表头文件 #include<stdio.h>
定义函数 int fputc(int c,FILE * stream);
函数说明 fputc 会将参数c 转为unsigned char 后写入参数stream 指定的文件中。
返回值 fputc()会返回写入成功的字符,即参数c。若返回EOF则代表写入失败。
范例 
复制代码
#include<stdio.h>