This blog is under construction

Friday 27 April 2012

rewind example in C

Header file:
    stdio.h

Synopsis:
     void rewind(FILE *stream);

Description:
     It is equivalent to fseek(fp, 0, SEEK_SET);  SEEK_SET - moves file pointer to the beginning of the file.


rewind function C example:


  #include<stdio.h>
  #include<string.h>
  int main() {
        char str[100];
        FILE *fp;
        fp = fopen("input.txt", "r");
        fgets(str, 10, fp);
        printf("%s\n", str);
        rewind(fp);
        fgets(str, 10, fp);
        printf("%s\n", str);
        fclose(fp);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/cpgms/exp$ cat input.txt
  This is fwrite example program

  jp@jp-VirtualBox:~/cpgms/exp$ ./a.out
  This is f
  This is f



No comments:

Post a Comment