Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using onlinegdb.com, write a c code, and show proof of the output that you are supposed to get, and explain which command line arguments you
Using onlinegdb.com, write a c code, and show proof of the output that you are supposed to get, and explain which command line arguments you are suppose to put to get the output. PLEASE SUBMIT ONE BIG CODE, THAT IS ALL TOGETHER.
NOTE YOU ARE NOT ALLOWED TO USE FTW OR ANY SIMILAR LIBRARY FUNCTION!
What to do
Write a C program myfind whose behavior resembles that of the system command ind.
myfind accepts the following parameters:
$ myfind filename startpath
where
filename is a substring that is matched against each filename in each directory that my ind
inspects. If a file name matches ilename or if the substring filename occurs within a file
name, the name of that file is printed.
startpath is an optional parameter that specifies the directory where myfind must start the
search. If this parameter is not specified, my ind starts in the current directory.
For each file whose name is a match, myfind must print its name and its mode.
For each directory in which myfind finds a match, it must print that directory's full path.
Test myfind using various directories on your computer attempting to match full and partial file names.
Sample files and directories are available in the class github repository. Below is a typical output produced
by myfind
I have this code, but i can not get the necessarry output.
#include
#include
#include
#include
#include
#include
Function prototypes
void searchdirectoryconst char startpath const char filename;
int mainint argc, char argv
if argc
fprintfstderr "Usage: s filename startpath
argv;
return EXITFAILURE;
const char filename argv;
const char startpath argc argv : ;
searchdirectorystartpath filename;
return EXITSUCCESS;
Function to convert mode to a string
void modetostringmodet mode, char str
sprintfstro mode & ;
strmode & SIRUSRr : ;
strmode & SIWUSRw : ;
strmode & SIXUSRx : ;
strmode & SIRGRPr : ;
strmode & SIWGRPw : ;
strmode & SIXGRPx : ;
strmode & SIROTHr : ;
strmode & SIWOTHw : ;
strmode & SIXOTHx : ;
str;
Function to search directories
void searchdirectoryconst char startpath const char filename
DIR dir opendirstartpath;
if dir
perroropendir;
return;
struct dirent entry;
while entry readdirdir NULL
if strcmpentrydname, strcmpentrydname,
continue;
char pathPATHMAX;
snprintfpath sizeofpathss startpath, entrydname;
struct stat statbuf;
if statpath &statbuf
perrorstat;
continue;
if SISDIRstatbufstmode
Print directory path if it contains a match
if strstrentrydname, filename
printfs
path;
Recursively search subdirectories
searchdirectorypath filename;
else
Print file details if it contains a match
if strstrentrydname, filename
char modestr;
modetostringstatbufstmode, modestr;
printfs s
path, modestr;
closedirdir;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started