title: Reading a .txt file in VS2010
body: <p>I am trying to read a text file and display the contents to the screen. The file is just a list of words. I have placed the .txt file in the tree of my project but the code will not open it. My question is, is the .txt file in the wrong place? Is fopen the correct function to do this? I'm going round in circles with this and it seems so simple! :(</p>
  
  <p>The file is stored in the directory under "ProjectName" -- Source Files -- File.txt</p>
  
  <p>My code so far is:</p>
  
  <pre><code>int main (void)
  {
  
  char word [30];
  
      FILE *fp;
  
      if ((fp = fopen("sort.txt", "r")) == NULL)
      {
          printf( "File could not be opened\n");
      }
      else
      {
          fscanf(fp, "%s", word);
  
          while (!feof(fp))
          {
              fscanf(fp, "%s", word);
          }
  
          fclose (fp);
      }
      return 0;
  }
  </code></pre>
  
  <hr>
  
  <p>Problem solved. I re-created a text file in my project by right clicking on Source Files then choosing Add New Item and choosing text file under the Utility option. I then copied my original text file data into it. The file was then created in the appropriate directory. Simple solution! Happy newbie-coder!!</p>