ls command
Tue May 07 2024 12:37:06 GMT+0000 (Coordinated Universal Time)
Saved by
@login123
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdlib.h>
int main() {
char dname[100];
DIR *p;
struct dirent *d;
printf("Enter directory name: ");
scanf("%s", dname);
p = opendir(dname);
if (p == NULL) {
perror("Cannot open directory");
exit(EXIT_FAILURE);
}
while ((d = readdir(p)) != NULL) {
printf("%s\n", d->d_name);
}
closedir(p);
return 0;
}
content_copyCOPY
Comments