title: Error checking fopen from argv[i] in C
body: <p>I have been trying to do error checking with my code to make sure that the argument given is a valid file. The following code:</p>
  
  <pre><code>int main(int argc, char *argv[]){
      for(int i = 1, i &lt;=argc, i++){
           FILE *fileIn = fopen(argv[i],"r");
           if(fileIn == NULL){
                  fprintf(stderr,"The file %s doesn't exist.",fileIn);
           }
           else if (fileIn != NULL){
               do a bunch of stuff, including printing out values from a struct
           }
  </code></pre>
  
  <p>The problem I am having is when I run my program I get this as an output:</p>
  
  <pre><code>The (null) file doesn't exist
  Output from else if loop
  </code></pre>
  
  <p>So basically, it is saying that fileIn is null and is not null at the same time. It is reading the file normally and doing it as it should, but it runs through the error each time. Is there any way to assign a pointer to argv[i or something? How is this happening? </p>