-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls_a.c
46 lines (45 loc) · 898 Bytes
/
ls_a.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<unistd.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<stdio.h>
#include<dirent.h>
#include<string.h>
#include<stdlib.h>
#include<errno.h>
int main(int argc, char const *argv[])
{
//printf("%s\n","hendn" );
DIR *dir;
struct dirent **file;
char cwd[1000];
getcwd(cwd,sizeof cwd);
dir=opendir(cwd);
if(dir!=NULL){
//printf("%s\n","hiii" );
int size=scandir(cwd,&file,0,alphasort);
int i=0;
while(i<size){
char *line=file[i]->d_name;
char a=line[0];
char b=line[1];
printf("%s ",line );
free(file[i]);
i++;
}
printf("%s\n","" );
free(file);
}
else{
//printf("%s\n","ooops" );
if(errno==ENOENT){
printf("%s\n","The directory specified in path does not exist." );
}
else if(errno==EACCES){
printf("%s\n","Search permission is denied for one of the components of path." );
}
else{
printf("%s\n","ERR" );
}
}
return 0;
}