I need to combine two programs that can do the following
(a) what ls command does and (b) to check each file name to print its content if its name has \".lst\" extension.
These are the two programs
Program - 1
/* * simple-ls.c * Extremely low-power ls clone. * ./simple-ls . */#include #include #include #include intmain(int argc, char **argv) { DIR *dp; struct dirent *dirp; if (argc != 2) { fprintf(stderr, \"usage: %s dir_name\n\", argv[0]); exit(1); } if ((dp = opendir(argv[1])) == NULL ) { fprintf(stderr, \"can't open '%s'\n\", argv[1]); exit(1); } while ((dirp = readdir(dp)) != NULL ) printf(\"%s\n\", dirp->d_name); closedir(dp); return(0);}
Program - 2
/* * Stripped down version of 'cat', using unbuffered I/O. * ./simple-cat < simple-cat.c */#include #include #include #define BUFFSIZE 32768intmain(int argc, char **argv) { int n; char buf[BUFFSIZE]; while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0) { if (write(STDOUT_FILENO, buf, n) != n) { fprintf(stderr, \"write error\n\"); exit(1); } } if (n < 0) { fprintf(stderr, \"read error\n\"); exit(1); } return(0);}
That is, you will design and implement this lscat.c program willdo what simple-ls.c program does (to loop through each entry in thedirectory to be printed), and the program checks whether an entryis a file name and its name contains a character-pattern (\".lst\" atthe end of the file name). If so, then it prints the file-content(that is, to open and print the content). For this part (to printthe file content) the program may use the code-segment of\"simple-cat\" program. When the program prints the file-content,please have a user-friendly heading to show the beginning and theend of the file content being printed) as shown below (or you mayhave your own heading).
*** Start of the file: sample.lst ***
...
*** End of the file: sample.lst ***
Thank You