使用C语言的opendir实现ls命令
#include<dirent.h>
#include<stdio.h>
void main(int argc,char *argv[])
{
DIR *dirp;
struct dirent *sdp;
argv[1]=".";
dirp=opendir("./");//读取当前目录
if(dirp==NULL){
perror("opendir error");
}
while(sdp=readdir(dirp)){
printf("%s\n",sdp->d_name);
}
printf("\n");
closedir(dirp);
}