YouTip LogoYouTip

C Function Rewind

# C Library Function - rewind() [![Image 3: C Standard Library - ](#) C Standard Library - ](#) ## Description The C library function **void rewind(FILE *stream)** sets the file position to the beginning of the file of the given stream **stream**. ## Declaration Here is the declaration for the rewind() function. void rewind(FILE *stream) ## Parameters * **stream** -- This is a pointer to a FILE object that identifies the stream. ## Return Value This function does not return any value. ## Example The following example demonstrates the usage of the rewind() function. #include int main(){ char str[] = "This is .com"; FILE *fp; int ch; /* Let's first write some content to 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);} Let us assume we have a text file **file.txt**, with the following content: This is .com Now let us compile and run the above program, this will produce the following result: This is .com This is .com [![Image 4: C Standard Library - ](#) C Standard Library - ](#)
← Sets SpopSets Smembers β†’