Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

The rewind() function

This function is used to bring the file indicator at the beginning of the file from the current position.

Syntax

void rewind (FILE *fp);

Example

#include<stdio.h>
int main()
{
    FILE *fp;
    int curr_pos;
    fp=fopen("D:\\C Programming\\file8.txt","r"); // file opened in
                                                   // read mode 
    if(fp==NULL)
    {
        printf("\n Unable to open the FILE");
        return 1;
    }
	
    fseek(fp, 6, SEEK_SET); // position indicator placed at 6th position
	
    curr_pos = ftell(fp);
    printf("\n Before rewinding position of the file indicator = %d",curr_pos);
	
    rewind(fp);  // moves the file position indicator at the beginning of the file
    curr_pos = ftell(fp);
    printf("\n\n After rewinding position of the file indicator = %d",curr_pos);
	
    fclose(fp);
    return 0;
}

Inside file8.txt

C Programming Language rewind Function in File Handling Example

Output

C Programming Language rewind Function in File Handling Example Output

Before rewinding position of the file indicator

C Programming Language rewind Function in File Handling Example 1

After rewinding position of the file indicator

C Programming Language rewind Function in File Handling Example 2
 

Leave a reply