#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if (argc != 2)
{
printf("usage: ls directory_name ");
exit(-1);
}
if ((dp = opendir(argv[1])) == NULL)
{
printf("can't open [%s] ", argv[1]);
exit(-2);
}
printf("==name== ==type== ");
while ((dirp = readdir(dp)) != NULL)
printf("%s %d ", dirp->d_name,dirp->d_type);
closedir(dp);
exit(0);
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if (argc != 2)
{
printf("usage: ls directory_name ");
exit(-1);
}
if ((dp = opendir(argv[1])) == NULL)
{
printf("can't open [%s] ", argv[1]);
exit(-2);
}
printf("==name== ==type== ");
while ((dirp = readdir(dp)) != NULL)
printf("%s %d ", dirp->d_name,dirp->d_type);
closedir(dp);
exit(0);
}