title: Basic file I/O of a ppm file
body: <p>I'm trying to write a program to read through a .ppm file and keep the data in a struct. To be able to do that though, I need to be able to open the file, which is not working so far. I'm obviously doing something wrong. Can you please take a look at the code and see if you can find out what's the problem?    </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int readFile(char *filename);
  
  int main(void)
  {
      readFile("myfile.ppm");
      return 0;
  }
  
  int readFile(char *filename)
  {
      int x = 0;
      FILE *pFile;
      pFile = fopen(filename, "rb");
      if(!pFile)
      {
          fprintf(stderr, "Unable to open file %s\n", filename);
          exit(1);
      }
  
      fscanf(pFile, "%d", &amp;x);
      fclose(pFile);
      printf("%d\n", x);
      return 0;
  }
  </code></pre>
  
  <p>This just gives me an "\n" on the stdout. Should I fscanf it into an array rather than an int?</p>
  
  <p>Based on your feedback I edited the code to scanning to two chars:</p>
  
  <pre><code>int readFile(char *filename)
  {
      char first, second = 0;
      FILE *pFile;
      pFile = fopen(filename, "rb");
      if(!pFile)
      {
          fprintf(stderr, "Unable to open file %s\n", filename);
          exit(1);
      }
  
      fscanf(pFile, "%c%c", &amp;first, &amp;second);
      fclose(pFile);
      printf("First: %c, Second: %c\n", first, second);
      return 0;
  }
  </code></pre>