//Tested on linux,ubuntu #include #include #include #include #include /*Main function start*/ int main(int argc, char *argv[]) { /*variable for buffer*/ struct stat statbuf; /*pointer variable declaration*/ DIR *dp; struct dirent *dirp; /*if we are not providing file path then it will take current directory as name*/ if(argc==1) { dp = opendir(\"./\"); } else { dp = opendir(argv[1]); } while ( (dirp=readdir(dp)) != NULL) { /*lstat - get symbolic link status * Please readabout lstat more*/ lstat(dirp->d_name, &statbuf); /*checking it is directory or not*/ if(S_ISDIR(statbuf.st_mode)) { /*it is printing directory name with /*/ printf(\"%s/ \ \", dirp->d_name); } else { /*If it is file then we are printing only name of file*/ printf(\"%s\ \", dirp->d_name); } } /*cosing directory pointer*/ closedir(dp); exit(0); } /*main function end*/ /**********output**********/ gopal@gopal:~/Desktop/chegg$ gcc directory.c gopal@gopal:~/Desktop/chegg$ ./a.out dLinkedList.c random.c jasmin/ LinkedStack.cpp VideoGame.java LinkedStack.cpp Client.class web.xml ../ TemplateMain.cpp Energy.py PrecondViolatedExcept.h CSA.cpp BoxofProduce.cpp ./ Unanswere/ Tree.c target/ readFile.c inventory.txt goodQuestion interest.c VideoGameManager.java Thanks a lot Solution //Tested on linux,ubuntu #include #include #include #include #include /*Main function start*/ int main(int argc, char *argv[]) { /*variable for buffer*/ struct stat statbuf; /*pointer variable declaration*/ DIR *dp; struct dirent *dirp; /*if we are not providing file path then it will take current directory as name*/ if(argc==1) { dp = opendir(\"./\"); } else { dp = opendir(argv[1]); } while ( (dirp=readdir(dp)) != NULL) { /*lstat - get symbolic link status * Please readabout lstat more*/ lstat(dirp->d_name, &statbuf); /*checking it is directory or not*/ if(S_ISDIR(statbuf.st_mode)) { /*it is printing directory name with /*/ printf(\"%s/ \ \", dirp->d_name); } else { /*If it is file then we are printing only name of file*/ printf(\"%s\ \", dirp->d_name); } } /*cosing directory pointer*/ closedir(dp); exit(0); } /*main function end*/ /**********output**********/ gopal@gopal:~/Desktop/chegg$ gcc directory.c gopal@gopal:~/Desktop/chegg$ ./a.out dLinkedList.c random.c jasmin/ LinkedStack.cpp VideoGame.java LinkedStack.cpp Client.class web.xml ../ TemplateMain.cpp Energy.py PrecondViolatedExcept.h CSA.cpp BoxofProduce.cpp ./ Unanswere/ Tree.c target/ readFile.c inventory.txt goodQuestion interest.c VideoGameManager.java Thanks a lot.