C Library Function-rewind ()

Source: Internet
Author: User
Tags rewind tutorialspoint

Description

The C library function void rewind (file *stream) sets the file position to the beginning of the file of the given Stream.

Declaration

Following is the declaration for Rewind () function.

void Rewind(*stream)    
Parameters
    • Stream −this is the pointer to a FILE object that identifies the stream.

Return Value

This function does no return any value.

Example

The following example shows the usage of the rewind () function.

#include <stdio.h>IntMain(){ CharStr[] = "This is tutorialspoint.com";FILE*Fp; IntCh; /* 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); }

Set the file position to the beginning, if it doesn ' t has this function, FP would point NULL, because above while (1) and Break if feof (FP) is true. Rewind(Fp);Printf("\ n"); While(1) {Ch=Fgetc(Fp if ( Feof ( fp) { break ;} Printf ( "%c" , Ch } Fclose (FP return (0 /span>

Let us assume we had a text file file.txt that has the following content−

This is tutorialspoint.  COM   

Now let us compile and run the above program to produce the following result−

This is Tutorialspoint.comthis is tutorialspoint.com

C Library Function-rewind ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.