title: Using fseek with a file pointer that points to stdin
body: <p>Depending on command-line arguments, I'm setting a file pointer to point either towards a specified file or stdin (for the purpose of piping). I then pass this pointer around to a number of different functions to read from the file. Here is the function for getting the file pointer:</p>
  
  <pre><code>FILE *getFile(int argc, char *argv[]) {
      FILE *myFile = NULL;
      if (argc == 2) {
          myFile = fopen(argv[1], "r");
          if (myFile == NULL)
             fprintf(stderr, "File \"%s\" not found\n", argv[1]);
      }
      else
          myFile = stdin;
      return myFile;
  }
  </code></pre>
  
  <p>When it's pointing to stdin, <code>fseek</code> does not seem to work. By that, I mean I use it and then use <code>fgetc</code> and I get unexpected results. Is this expected behavior, and if so, how do I move to different locations in the stream?</p>
  
  <p>For example:</p>
  
  <pre><code>int main(int argc, char *argv[]) {
      FILE *myFile = getFile(argc, argv); // assume pointer is set to stdin
      int x = fgetc(myFile); // expected result
      int y = fgetc(myFile); // expected result
      int z = fgetc(myFile); // expected result
  
      int foo = bar(myFile); // unexpected result
  
      return 0;
  }
  
  int bar(FILE *myFile) {
      fseek(myFile, 4, 0);
      return fgetc(myFile);
  }
  </code></pre>