rewind

C程序中的庫函數

C程序中的庫函數,功能是將文件內部的指針重新指向一個流的開頭

基本內容


函數名:rewind
功能:將文件內部的位置指針重新指向一個流(數據流/文件)的開頭
注意:不是文件指針而是文件內部的位置指針,隨著對文件的讀寫文件的位置指針(指向當前讀寫位元組)向後移動。而文件指針是指向整個文件,如果不重新賦值文件指針不會改變。
rewind函數作用等同於(void)fseek(stream,0L,SEEK_SET);
用法:void rewind(FILE*stream);
頭文件:stdio.h
返回值:無

英文解釋


A statement such as
rewind(cfptr);
causes a program's file position--which indicates the number of the next byte in the file to be read or written-- to be repositioned to the beginnning of the file pointed to by cfptr.

程序例


#include
#include
int main(void)
{
FILE*fp;
char fname="TXXXXXX",*newname,first;
newname=mktemp(fname);
fp=fopen(newname,"w+");
if(NULL==fp)
return 1;
fprintf(fp,"abcdefghijklmnopqrstuvwxyz");
rewind(fp);
fscanf(fp,"%c",&first);
printf("The first character is:%c\n",first);
fclose(fp);
remove(newname);
return 0;
}