English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
rewind()函数将文件指针设置在流的开始。如果必须多次使用流,这很有用。
语法:
void rewind(FILE *流)
文件:file.txt
这是一个简单的文本
程序:rewind.c
#include<stdio.h> #include<conio.h> void main(){ FILE *fp; char c; clrscr(); fp=fopen("file.txt","r"); while((c=fgetc(fp))!=EOF){ printf("%c",c); } rewind(fp);//将文件指针移到文件开头 while((c=fgetc(fp))!=EOF){ printf("%c",c); } fclose(fp); getch(); }
输出:
这是一个简单的文本这是一个简单的文本
As you can see, the rewind() function moves the file pointer to the beginning of the file, which is why 'this is simple text' needs to be printed.2If the rewind() function is not called, 'this is simple text' will be printed only once.