rewind
来自cppreference.com
| 在标头 <stdio.h> 定义
|
||
| |
||
移动文件位置指示器到给定文件流的起始。
函数等价于 fseek(stream, 0, SEEK_SET);,但它会清除文件尾和错误指示器。
此函数丢弃任何来自先前对 ungetc 调用的效果。
参数
| stream | - | 要修改的文件流 |
返回值
(无)
示例
此例演示如何读文件二次
运行此代码
#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;
}
输出:
0123456789
0123456789