#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\n");
exit(-1);
}
if ((dp = opendir(argv[1])) == NULL)
{
printf("can't open [%s]\n", argv[1]);
exit(-2);
}
printf("==name==\t==type==\n");
while ((dirp = readdir(dp)) != NULL)
printf("%s\t%d\n", 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\n");
exit(-1);
}
if ((dp = opendir(argv[1])) == NULL)
{
printf("can't open [%s]\n", argv[1]);
exit(-2);
}
printf("==name==\t==type==\n");
while ((dirp = readdir(dp)) != NULL)
printf("%s\t%d\n", dirp->d_name,dirp->d_type);
closedir(dp);
exit(0);
}