include stdio include dirent include sys types include sys stat includ

 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
void swap( char *a, char *b)
{
char *tmp;
strcpy(tmp,a);
strcpy(a,b);
strcpy(b,tmp);
}
int main(void)
{
char *string[PATH_MAX];
struct stat st;
struct dirent *dirinf;
DIR *hdir;
hdir = opendir(".");
int i = 0;
short int exit = 0;
while (dirinf = readdir(hdir))
{
if(S_ISDIR(st.st_mode))
continue;
stat(dirinf->d_name, &st);
string[i] = dirinf->d_name;
i++;
}
int l;
for (l = 0; exit != 1; l++)
{
exit = 1;
int j;
for (j = 0; j<i-1; j++)
{
int k;
for (k = j; k<i+1; k++)
{
if (*string[j] > *string[k])
{
swap(string[j],string[k]);
}
}
for (j = 0; j<i; j++)
if ( *string[j] != '\0' )
{
string[j]++;
exit = 0;
}
}
}
int m;
for (m = 0; m<i; m++)
printf("\%s\t", string[m]);
closedir(hdir);
return 0;
}