If you want to know more on rewind in c then read this blog post.
What is rewind in c programming?
rewind function in c sets the file position to the beginning of a file.
This function does not return any value.
It is defined in stdio.h header file.
Prototype
#include<stdio.h>
void rewind(FILE *stream);
Parameters of rewind in c
rewind function takes a file pointer as a parameter.
Return value of rewind in c
rewind function does not return any value.
Example program for rewind in c
#include<stdio.h>
int main()
{
FILE *fpointer;
char n;
fpointer=fopen("scholar.txt","r");
while(!feof)
printf("%c \n",n);
rewind(fpointer);
printf("after rewind \n");
while(!feof)
printf("%c \n",n);
fclose(fpointer);
return 0;
}
Code explanantion
The file pointer is moved to the beginning of the file by calling the rewind function. The content of the file is printed onto the console.
Difference between rewind and fseek in c
rewind function in c sets the file position to the beginning of a file. fseek is used to change the file pointer to the specified stream.
rewind function does not return any value. fseek function returns zero in operation is successful otherwise a nonzero value.
rewind function takes one argument. fseek takes three arguments.
rewind function moves the pointer to the beginning of a file. fseek moves the pointer depending upon whence argument value specified.
Prototypes are as follows
void rewind(FILE *stream);
int fseek(FILE *strm,long int offst,int whnce);
rewind in c | fseek in c |
Sets the file position to the beginning of a file. | Used to change the file pointer to the specified stream. |
void rewind(FILE *stream); | int fseek(FILE *strm,long int offst,int whnce); |
Does not return any value. | Returns zero in operation is successful otherwise a nonzero value. |
Difference between rewind and ftell in c
rewind function in c sets the file position to the beginning of a file. ftell in c is used to get the total size of a file after moving the file pointer to the end of a file.
rewind function does not return any value. ftell returns the current file pointer position from starting of a file.
Prototypes are as follows
void rewind(FILE *stream);
long int ftell(FILE *strm);
rewind in c | ftell in c |
Sets the file position to the beginning of a file. | Used to get total size of a file after moving file pointer to the end of a file. |
void rewind(FILE *stream); | long int ftell(FILE *strm); |
Does not return any value. | Returns the current file pointer position from starting of a file. |
People also ask for
What is rewind in c?
rewind function moves the pointer to the beginning of a file. It is defined in stdio.h header file.
What are all the errors does rewind function returns?
rewind function returns no error. It clears the error and EOF for stream.
Why does fseek better than rewind in c?
fseek is preferred than rewind in c because rewind doesn’t return an integer value indicating whether the operation is succeeded or not.