From 89ba57eb2b9e024996da29ba5e429adf15b27a6d Mon Sep 17 00:00:00 2001 From: Matthew Strapp Date: Mon, 19 Oct 2020 07:55:41 -0500 Subject: add breakouts --- csci4061/101220_breakout/exercise.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'csci4061/101220_breakout/exercise.c') diff --git a/csci4061/101220_breakout/exercise.c b/csci4061/101220_breakout/exercise.c index 5021142..be8bb11 100644 --- a/csci4061/101220_breakout/exercise.c +++ b/csci4061/101220_breakout/exercise.c @@ -9,9 +9,10 @@ #include int numOfEntries(char* path) { - /* - Count the number of entries in path - */ + int entries = 0; + while (readdir(path) != NULL) { + entries++; + } return entries; } int main(int argc, char** argv){ @@ -27,7 +28,20 @@ int main(int argc, char** argv){ return -1; } struct dirent* entry; - + DIR* current = dir; + +while ((entry = readdir(dir)) != NULL) { + if (entry->d_type == "DT_DIR"){ + printf("Directory: %s\n", entry->d_name); + printf(" Entries: %d\n", numOfEntries(entry)); + } else if (entry->d_type == "DT_REG") { + printf("Regular File: %s\n", entry->d_name); + printf(" Owner: %d\n"); + printf(" Size: %f\n"); + } else { + printf("%s\n", entry -> d_name); + } + } /* Iterate through the elements in argv[1] Refer the ls example in slides if you have any doubts -- cgit v1.2.3