Question: #include #include #include #include #include void listFiles ( const char * dirPath ) ; int main ( int argc, char const * argv [ ]
#include
#include
#include
#include
#include
void listFilesconst char dirPath;
int mainint argc, char const argv
if argc
No argument, print the current working directory WITHOUT recursion
char cwd;
if getcwdcwd sizeofcwd NULL
listFilescwd;
else
perrorgetcwd this is error";
exitEXITFAILURE;
else if argc
Argument provided, print that directory RECURSIVELY
listFilesargv;
else
Too many arguments, display an error message
fprintfstderr "Usage: s directory
argv;
exitEXITFAILURE;
return EXITSUCCESS;
void listFilesconst char dirPath
DIR dir;
struct dirent entry;
if dir opendirdirPath NULL
while entry readdirdir NULL
if entrydname
Ignore hidden files and directories
printfs
entrydname;
closedirdir;
else
perrorthere is no subdir it's an error";
exitEXITFAILURE;
re witre my code with diffrent stuatuer. code in c
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
