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

  1. #include <stdio.h>
  2. #include "process_dir.h"
  3. void print_dir(filestruct in) {
  4. for (size_t i = 0; i < in.depth-1; ++i) {
  5. printf(" ");
  6. }
  7. printf("├ %s\n", in.name);
  8. for (size_t i = 0; i < in.depth-1; ++i) {
  9. printf(" ");
  10. }
  11. printf("└───┐\n");
  12. }
  13. void print_file(filestruct in) {
  14. for (size_t i = 0; i < in.depth; ++i) {
  15. printf(" ");
  16. }
  17. printf("│ %s\n", in.name);
  18. }
  19. int main (int argc, char **argv) {
  20. char *start = (argc > 1) ? argv[1] : ".";
  21. printf("Tree for %s:\n", start ? start : "the current directory");
  22. process_dir(.name=start, .file_action=print_file, .directory_action=print_dir);
  23. }