void rewind( FILE *stream ); | | |
| | |
移动文件位置指示器到给定文件流的起始。
函数等价于 fseek(stream, 0, SEEK_SET);,但它会清除文件尾和错误指示器。
此函数丢弃任何来自先前对 ungetc 调用的效果。
参数
返回值
(无)
示例
此例演示如何读文件二次
#include <stdio.h>
char str[20];
int main(void)
{
FILE *f;
char ch;
f = fopen("file.txt", "w");
for (ch = '0'; ch <= '9'; ch++) {
fputc(ch, f);
}
fclose(f);
f = fopen("file.txt", "r");
fread(str, 1, 10, f);
puts(str);
rewind(f);
fread(str, 1, 10, f);
puts(str);
fclose(f);
return 0;
}
输出:
引用
- C11 标准(ISO/IEC 9899:2011):
- 7.21.9.5 The rewind function (第 338 页)
- C99 标准(ISO/IEC 9899:1999):
- 7.19.9.5 The rewind function (第 304 页)
- C89/C90 标准(ISO/IEC 9899:1990):
- 4.9.9.5 The rewind function
参阅