title: reading in a file line by line - where is the file?
body: <p>Im new to using GNU C by using Terminal on a Mac.</p>
  
  <p>I've used a standard piece of code to read in a file line by line and referring out to a file by "file.txt".</p>
  
  <p>I can compile the source but when I execute the code it can't find file.txt. I have put the file in the the same directory as the source and executable file. Should I be adding a full directory path. I tried :-</p>
  
  <p>"/Users/Swiss/documents/swdev/projects/code_ex/file.txt"</p>
  
  <p>but that comes up with the same error as just using "file.txt".</p>
  
  <p>The error I get is:-</p>
  
  <p>-bash: ./read_file.lbl: No such file or directory</p>
  
  <p>and am assuming its the file.txt it can't find - or is it something else?</p>
  
  <p>The code is:-</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main ( void )
  {
     static const char filename[] =  "/Users/Swiss/documents/swdev/projects/code_ex/file.txt";
     FILE *file = fopen ( filename, "r" );
     if ( file != NULL )
     {
        char line [ 128 ]; /* or other suitable maximum line size */
        while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */
        {
           fputs ( line, stdout ); /* write the line */
        }
        fclose ( file );
     }
     else
     {
        perror ( filename ); /* why didn't the file open? */
     }
     return 0;
  }
  </code></pre>
  
  <p>Any help will be warmly welcomed. </p>