Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need this in Linux, Please help 1. How to use “nd” command to nd dirent.h in /

ID: 3842849 • Letter: I

Question

I need this in Linux, Please help

1. How to use “nd” command to nd dirent.h in /usr? This header le denes an struct for format of directory entries called “dirent”.
2. In your code, dene a pointer to the struct “dirent”.
3. dirent.h denes a struct called DIR. What is denition of DIR according to dirent.h?
4. dirent.h denes a function called opendir. What is denition of opendir according to dirent.h?
5. What is the description of opendir according to “man”?
6. Include sys/type.h as a header le in your code.
7. How to use “nd” command to nd sys/type.h in /usr?
8. What sys/type.h contains?
9. Dene a pointer with type directory stream (DIR).
10. The program needs to get an argument for the directory name. Check if the number of arguments (argc) is two, otherwise prints an error and exits the program.
1
11. Your program needs to open the directory given by argument argv[1]. Store it in your dened directory stream. Also check if the directory name is opened correctly, otherwise quit the program with an error message.
12. Your program should read all the entries in this directory, and then print all the le names and their sizes on the console. You may need to use “stat” function.
13. Your program should close the dened directory stream and check if the le is closed correct

Explanation / Answer

1. You need to use it as find <folderpath> <options> <filename>.

In this case it is:

sudo find /usr -name dirent.h

4. According to one of those man pages on the internet opendir -

If called like this DIR *opendir(const char *dirname);

The opendir() function opens a directory stream of given directory named by the dirname argument. The directory stream is positioned at the first entry.

3. DIR is a dirent data stucture having the following members:

The above is from a manpage too.

2. Here is how I defined a new pointer to struct dirent.

#include "dirent.h"
#include <iostream>

using namespace std;

int main()
{
   // Creating a pointer called for struct dirent.  
   dirent *my_dirent = new dirent;
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote