2
    #include <stdio.h>
    #include <stdlib.h>

    int main()
    {
     FILE *file1;
     char c;
     file1=fopen("find1.txt","r");


      if(file1==NULL)
       {
            printf("\n file doesnt exist\n");
            exit(1);
       }

      else
      {
          while(1)
          {

              c=fgetc(file1);

              if(feof(file1))
              {

                  break;
              }


             putc(c,stdout);

          }
      }


  }

what i think how this code work is fgetc() take a character from file pointed by filepointer and put that character in "c".Next time it takes the next character from the file and put that in "c". does the filepointer get increment and point to next character?or it is handeled in any other way ?

ekaf
  • 153
  • 2
  • 13
  • 3
    `file1` is an opaque pointer which possibly points to a `struct` which may contain many fields out of which some may have been changed. (For example incremented) on each `fgetc` – Mohit Jain Jul 12 '16 at 12:22
  • 2
    `FILE *` is just a pointer to some memory location and it won't be changed by RW operations on file. But file current position is incremented automatically after each read / write. – Sergio Jul 12 '16 at 12:22
  • @serhio that means i can track the address while reading from file ?i want to find a word in a file . – ekaf Jul 12 '16 at 12:26
  • The C library is designed *on purpose* to hide the contents of `FILE` from you. The only supported way to use it is with the functions in the C library. Look at the library functions for reading and setting file position. – Zan Lynx Jul 12 '16 at 14:28
  • Looks useful for file positioning information: http://stackoverflow.com/questions/12119132/ftello-fseeko-vs-fgetpos-fsetpos – Zan Lynx Jul 12 '16 at 14:31

1 Answers1

0

The file1 pointer itself does not get incremented. The FILE object that it points to will contain (among other things) a pointer to the current stream position, and that will be updated as you read or write the file.

John Bode
  • 119,563
  • 19
  • 122
  • 198