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..
Could anyone pls check the code for any errors....thnx
#include<stdio.h>
#include<dirent.h>
#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->d_name);
if(ptr=fopen(dent->d_name,"r"))
{
print("\tFILE\n");
fclose(ptr);
}
else
printf("\t DIRECTORY\n");
}
close(dir);
}
else
printf("ERROR OPENIN DIRECTORY");
}