/
main.c
43 lines (34 loc) · 791 Bytes
/
main.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
/*
* Main logic behind the averageLS program. First calls recursive_search to find
* information on the average length of file names, then calls
* print_files_with_long_names to print file names that are above the average.
*
*/
#include "average_functions.h"
int main(int argc, char * argv[])
{
const char * pathname;
if (argc >= 2)
{
pathname = argv[1];
}
else
pathname = getenv("PWD");
int * info = malloc(2*sizeof(int));
info[0] = 0;
info[1] = 0;
int i = recursive_search(pathname, info);
if (i < 0)
{
return (-1);
}
int average = info[0]/info[1];
printf("Starting printing of files, average length of name: %d\n", average);
fflush(stdout);
if ( (i = print_files_with_long_names(pathname, average)) < 0)
{
free(info);
return (1);
}
free(info);
}