title: Accessing Directories in C
body: <p>The program is to open a directory and to display the name of the files...
  i.e if there is a file..it should say  FILE....else DIRECTORY..
  but the program displays all the files as directory..</p>
  
  <p>Could anyone pls check the code for any errors....thnx </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;dirent.h&gt;
  #define DIR_path "root/test"      
  main()
   {
     DIR *dir;
     dir=opendir(DIR_PATH);
     printf("THe files inside the directory :: \n");
  
    struct dirent *dent;
    if(dir!=NULL)
     {
  
         while((dent=readdir(dir)))
           {
              FILE *ptr;
              printf(dent-&gt;d_name);
  
                if(ptr=fopen(dent-&gt;d_name,"r"))
                  {
                       print("\tFILE\n");
                       fclose(ptr);
                  }
                else
                      printf("\t DIRECTORY\n");
          }
             close(dir);
      }
      else
              printf("ERROR OPENIN DIRECTORY");
  
  }
  </code></pre>