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 xuhuhu.com
現在讓我們來編譯和運行上面的程式,這將產生以下結果:
This is xuhuhu.com This is xuhuhu.com
上一篇:
rename() - C語言庫函數
下一篇:
setbuf() - C語言庫函數