Dotcpp  >  编程教程  >  stdio.h头文件  >  C语言rewind()函数:将文件指针重新指向一个流的开头

C语言rewind()函数:将文件指针重新指向一个流的开头

点击打开在线编译器,边学边练

函数名: rewind

头文件:<stdio.h>

函数原型: int rewind(FILE *stream);

功 能: 将文件指针重新指向一个流的开头

参数: FILE *stream  要操作的流

返回值:没有返回值    


程序例: 即将字符串写入文件,获取文件指针的长度,再调用rewind函数,获取文件//指针的长度,并将结果输出

#include<stdio.h>

int main(void){

   FILE *fp=fopen("D:\\a.txt","w+");

   if(!fp){

      printf("can not open the file\n");

      return 0;

   }

   fprintf(fp,"abcdefghijklmnopqrstuvwxyz");

   int first=ftell(fp);

   rewind(fp);

   int second=ftell(fp);

   printf("First pointer is %d,after call the rewind() is %d\n",first,second);

   fclose(fp);

   remove("D:\\a.txt");

   return 0;

}

 

运行结果

First pointer is 26,after call the rewind() is 0.



本文固定URL:https://www.dotcpp.com/course/531

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)