Fossexp 12

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

CSE (R13@II.

B-Tech II-Sem) EXP-12


Write a C program that simulates ls Command

[Krishnasai@H foss]$ cat 12ls2.c Output:


#include<stdio.h> [Krishnasai@H foss]$ ./a.out
#include<dirent.h> Enter directory name
#include<stdlib.h> /home/CSESTAFF/krishna/foss
int main() pow.sh
{ ex9
char dirname[10]; myfile2
DIR*p; lll
struct dirent *d; mesg.txt
printf("Enter directory name\n"); 8b.sh
scanf("%s",dirname); lak
p=opendir(dirname); 12ls.c
if(p==NULL) login.sh
{ myfile1
perror("Cannot find directory"); login2.sh
exit(-1); deleteline.sh
} gsalary.sh
while(d=readdir(p)) krishnasai
printf("%s\n",d->d_name); [Krishnasai@H foss]$
return 0;
}

Program:
[Krishnasai@H foss]$ cat 12ls.c
#include<stdio.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<dirent.h>
int main(int argc,char *argv[])
{
DIR *dp;
struct dirent *sd;
dp=opendir(argv[1]);
while((sd=readdir(dp))!=NULL)
{
printf("%s\t",sd->d_name);
}
closedir(dp);
}
Output: [Krishnasai@H foss]$ cc 12ls.c
[Krishnasai@H foss]$ ./a.out /home/CSESTAFF/krishna/foss
pow.sh ex9 myfile2 lll mesg.txt 8b.sh lak 12ls.c login.sh . myfile1
login2.sh deleteline.sh gsalary.sh k3 10cfile.c lllog.sh 12ls2.c krishnasai

bphanikrishna.wordpress.com
FOSSLAB Page 1 of 1

You might also like