Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

29 lines
646 B

#include <stdio.h>
#include "process_dir.h"
void print_dir(filestruct in) {
for (size_t i = 0; i < in.depth-1; ++i) {
printf(" ");
}
printf("├ %s\n", in.name);
for (size_t i = 0; i < in.depth-1; ++i) {
printf(" ");
}
printf("└───┐\n");
}
void print_file(filestruct in) {
for (size_t i = 0; i < in.depth; ++i) {
printf(" ");
}
printf("│ %s\n", in.name);
}
int main (int argc, char **argv) {
char *start = (argc > 1) ? argv[1] : ".";
printf("Tree for %s:\n", start ? start : "the current directory");
process_dir(.name=start, .file_action=print_file, .directory_action=print_dir);
}