title: Open directory using C
body: <p>I am accepting the path through command line input.</p>
  
  <p>When I do</p>
  
  <pre><code>dir=opendir(args[1]);
  </code></pre>
  
  <p>it doesn' t enter the loop...i.e <code>dir==null</code>...</p>
  
  <p>How do I pass the command line input to dir pointer?</p>
  
  <pre><code>void main(int c,char **args)
  {
      DIR *dir;
      struct dirent *dent;
      char buffer[50];
      strcpy(buffer, args[1]);
      dir = opendir(buffer);   //this part
      if(dir!=NULL)
      {
          while((dent=readdir(dir))!=NULL)
              printf(dent-&gt;d_name);
      }
      close(dir);
  }
  
  ./a.out  /root/TEST is used to run the program..
  ./a.out --&gt; to execute the program
  /root/TEST --&gt; input by the user i.e valid path
  </code></pre>