- 文件访问
fopen:FILE *fopen(const char *filename, const char *mode)
使用给定的模式 mode 打开 filename 所指向的文件。
freopen:FILE *freopen(const char *filename, const char *mode, FILE *stream)
把一个新的文件名 filename 与给定的打开的流 stream 关联,同时关闭流中的旧文件。
fflush:int fflush(FILE *stream)
刷新流 stream 的输出缓冲区。
fclose:int fclose(FILE *stream)
关闭流 stream。刷新所有的缓冲区。stream是什么? - 二进制输入/输出
fread:size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
从给定流 stream 读取数据到 ptr 所指向的数组中。
fwrite:size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
把 ptr 所指向的数组中的数据写入到给定流 stream 中。 - 非格式化输入/输出
fgetc: int fgetc(FILE *stream)
从指定的流 stream 获取下一个字符(一个无符号字符),并把位置标识符往前移动。
getc: int getc(FILE *stream)
从指定的流 stream 获取下一个字符(一个无符号字符),并把位置标识符往前移动。
fputc:int fputc(int char, FILE *stream)
把参数 char 指定的字符(一个无符号字符)写入到指定的流 stream 中,并把位置标识符往前移动。
putc:int putc(int char, FILE *stream)
把参数 char 指定的字符(一个无符号字符)写入到指定的流 stream 中,并把位置标识符往前移动。
ungetc:int ungetc(int char, FILE *stream)
把字符 char(一个无符号字符)推入到指定的流 stream 中,以便它是下一个被读取到的字符。
fgets:char *fgets(char *str, int n, FILE *stream)
从指定的流 stream 读取一行,并把它存储在 str 所指向的字符串内。当读取 (n-1) 个字符
fputs:int fputs(const char *str, FILE *stream)
把字符串写入到指定的流 stream 中,但不包括空字符。 - 格式化输入/输出
scanf:int scanf(const char *format, …)
从 stdin(标准输入) 读取格式化输入。
fscanf: int fscanf(FILE *stream, const char *format, …)
从流 stream 读取格式化输入。
sscanf:int sscanf(const char *str, const char *format, …)
从字符串读取格式化输入。
printf:int printf(const char *format, …)
发送格式化输出到 stdout(标准输出)。
fprintf:int fprintf(FILE *stream, const char *format, …)
发送格式化输出到流 stream 中。
sprintf:int sprintf(char *str, const char *format, …)
发送格式化输出到字符串。
perror:void perror(const char *str)
把一个描述性错误消息输出到标准错误 stderr。首先输出字符串 str,后跟一个冒号,然后是一个空格。 - 文件定位
ftell: long int ftell(FILE *stream)
返回给定流 stream 的当前文件位置。
fseek: int fseek(FILE *stream, long int offset, int whence)
设置流 stream 的文件位置为给定的偏移 offset,参数 offset 意味着从给定的 whence 位置查找的字节数。
fgetpos: int fgetpos(FILE *stream, fpos_t *pos)
获取流 stream 的当前文件位置,并把它写入到 pos。
fsetpos: int fsetpos(FILE *stream, const fpos_t *pos)
设置给定流 stream 的文件位置为给定的位置。参数 pos 是由函数 fgetpos 给定的位置。
rewind:void rewind(FILE *stream)
设置文件位置为给定流 stream 的文件的开头。 - 错误处理
feof:int feof(FILE *stream)
测试给定流 stream 的文件结束标识符。
ferror:int ferror(FILE *stream)
测试给定流 stream 的错误标识符。 - 文件操作
remove:int remove(const char *filename)
删除给定的文件名 filename,以便它不再被访问。
rename: int rename(const char *old_filename, const char *new_filename)
把 old_filename 所指向的文件名改为 new_filename。
tmpfile:FILE *tmpfile(void)
以二进制更新模式(wb+)创建临时文件。
C语言初学者之stdio.h各函数的用法
最新推荐文章于 2025-06-19 16:13:40 发布