English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C 语言基础教程

C 语言流程控制

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C 语言结构体

C 语言文件

C 其他

C 语言参考手册

C File rewind() Function

rewind()函数将文件指针设置在流的开始。如果必须多次使用流,这很有用。

语法:

void rewind(FILE *流)

文件:file.txt

这是一个简单的文本

程序:rewind.c

#include<stdio.h>  
#include<conio.h>  
void main(){  
    FILE *fp;  
    char c;  
    clrscr();  
    fp=fopen("file.txt","r");  
      
    while((c=fgetc(fp))!=EOF){  
        printf("%c",c);  
    }  
      
    rewind(fp);//将文件指针移到文件开头
      
    while((c=fgetc(fp))!=EOF){  
        printf("%c",c);  
    }  
      
    fclose(fp);    
    getch();    
}

输出:

这是一个简单的文本这是一个简单的文本

As you can see, the rewind() function moves the file pointer to the beginning of the file, which is why 'this is simple text' needs to be printed.2If the rewind() function is not called, 'this is simple text' will be printed only once.