Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write in C++ Please write in C++ Task 2: Printing the time that the file path was created (50 points) The stat system call

Please write in C++

image text in transcribed

Please write in C++

Task 2: Printing the time that the file path was created (50 points) The stat system call can access a file by name and retrieve file status information. It is given by: int stat (const char *pathname, struct stat *buf); This system call returns a stat structure (both the function and struct are called stat), which contains the following fields: struct stat dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* inode number */ mode_tst_mode; /* protection */ nlink_t st_nlink; /* number of hard links */ uid_t st_uid; * user ID of owner */ gid_t st_gid; / group ID of owner */ dev_t st_rdev; /* device ID (if special file) */ off_t st_size; /* total size, in bytes */ blksize_t st_blksize; /blocksize for file system 1/0 */ blkcnt_t st_blocks; /* number of 512B blocks allocated */ time_t st_atime; /* time of last access / time_t st_mtime; /* time of last modification */ time_t st_ctime; /* time of last status change */ On success, zero is returned. On error, -1 is returned, and errno is set appropriately. The following program displays the time that the file path was last accessed. Type in and complete the following program on the computer. Save it as printaccess.c. Compile the program, then execute it by giving it a path name as an argument. printaccess.c: #include #include #include int main (int argc, char *argv[]) { // define an instance of struct stat (don't use a pointer). // Use the stat function store the status of the file in your stat struct // stat takes a pointer, so pass your struct by reference with & if ( == -1) { // use perror to print error message then exit program } // print the last access time for the file using defined instance of // struct stat. ctime requires a pointer, hence the & below. printf ("%s last accessed at %s", argv[1], ctime(& .st_atime)); }

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

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions