返回值
此函数不返回任何值。
示例
以下示例显示rewind()函数的用法-
#include <stdio.h>
int main () {
char str[] = "This is cainiaoya.com";
FILE *fp;
int ch;
/* First let's write some content in the file */
fp = fopen( "file.txt" , "w" );
fwrite(str , 1 , sizeof(str) , fp );
fclose(fp);
fp = fopen( "file.txt" , "r" );
while(1) {
ch = fgetc(fp);
if( feof(fp) ) {
break ;
}
printf("%c", ch);
}
rewind(fp);
printf("\n");
while(1) {
ch = fgetc(fp);
if( feof(fp) ) {
break ;
}
printf("%c", ch);
}
fclose(fp);
return(0);
}
让我们假设我们有一个文本文件file.txt,具有以下内容-
现在让我们编译并运行上述程序以产生以下结果-
This is cainiaoya.com
This is cainiaoya.com