rewind() – C语言库函数
C库函数 void rewind(FILE *stream) 设置给定流的文件的开头的文件位置。
声明
以下是声明rewind() 函数。
void rewind(FILE *stream)
参数
-
stream -- 这是一个文件对象的标识流的指针。
返回值
这个函数不返回任何值。
例子
下面的例子演示了如何使用rewind() 函数。
#include<stdio.h>int main(){ FILE *fp;int ch; fp = fopen("file.txt","r");if( fp != NULL ){while(!feof(fp)){ ch = fgetc(fp); printf("%c", ch);} rewind(fp);while(!feof(fp)){ ch = fgetc(fp); printf("%c", ch);} fclose(fp);}return(0);}
假设我们有一个文本文件file.txt中有以下内容:
This is xyhtml5.com
现在让我们来编译和运行上面的程序,这将产生以下结果:
This is xyhtml5.com This is xyhtml5.com