title: Reading a file name from piped command
body: <p>So I'm trying to get the C program to read a filename from the command line in the following format:
  cat (filename path) | (program name)</p>
  
  <p>i can get it to read the name of the input file when its entered as a command line argument, but it won't read from the concatenated argument</p>
  
  <p>here's the code, right now its reading the name of the file as if written after the program name on the command line.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  //initialize file pointer
  FILE *file;
  
  //initialize global variables
  #define DEFAULT_LEN 70
  
  //main
  int main(int argv, char *argc[]){
  
   //open File for reading
   file = fopen (argc[1],"r");
   //test for failure of file open, if failed, print message, quit
   if(file == NULL){
        printf("I'm sorry Dave, I'm araid I can't do that.\n");
    printf("Open the file \"%s\" that is.\n", argc[1]);
    return(0);
   }
  
   //read the first line of a file into an array
   char temp[DEFAULT_LEN]; //where the read data is put
   fgets(temp,DEFAULT_LEN,file); //stops at DEFAULT_LEN on \n
  
   //print out temp
   printf("%s\n", temp);
  
   //close file, return 0 for main
   fclose(file);
   return(0);
  }
  </code></pre>
  
  <p>any help would be appreciated</p>