Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NEEDS DONE IN C, NO OTHER LANGUAGE. ALSO NEEDS TO BE ABLE TO COMPILE IN GCC Extend the readdir program to traverse the file hierarchy

NEEDS DONE IN C, NO OTHER LANGUAGE. ALSO NEEDS TO BE ABLE TO COMPILE IN GCC

Extend the readdir program to traverse the file hierarchy recursively and list all the sub directories and the files in these sub directories. Note that you have to modify the given readdir.c (or readdir_v2.c) program to use a function to perform the file traversal and then invoke it recursively.

---------------------------------------------------------------------------------------------------------------

readdir.c:

#####################

#include #include #include

int main (int argc, char **argv) { struct dirent *dirent; DIR *parentDir;

if (argc < 2) { printf ("Usage: %s ", argv[0]); exit(-1); } parentDir = opendir (argv[1]); if (parentDir == NULL) { printf ("Error opening directory '%s' ", argv[1]); exit (-1); } int count = 1; while((dirent = readdir(parentDir)) != NULL){ printf ("[%d] %s ", count, (*dirent).d_name); count++; } closedir (parentDir); return 0; } ###########################################

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

Students also viewed these Databases questions

Question

Design Capacity can be modified True False

Answered: 1 week ago

Question

Explain exothermic and endothermic reactions with examples

Answered: 1 week ago

Question

Write a short note on rancidity and corrosiveness.

Answered: 1 week ago

Question

Understand why empowerment is so important in many frontline jobs.

Answered: 1 week ago