Create Linux ls command C Program

By | December 18, 2022

Create Linux ls command C Program – Write a C program under Windows Operating System to create or simulate linux ls command.

Create Linux ls command C Program

 

Program code

#include<stdio.h>
#include<dirent.h>
int main(int argc, char **argv)
{
DIR *dp;
struct dirent *link;
dp=opendir(argv[1]);
printf("\n contents of the directory %s are \n", argv[1]);
while((link=readdir(dp))!=0)
printf("%s\n",link->d_name);
closedir(dp);
}

Output

 contents of the directory programms are
.
..
arrayio.c
arraymaxpointer.cpp
arraysumpointer.cpp

--------------------------------
Process exited after 2.519 seconds with return value 0
Press any key to continue . . .

You may also like OS Lab Practicals:

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *