Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C/shell programming Task 1: Printing File Names using Dirent Library: (50points) Here we want to access a Linux directory using C. To do so we

C/shell programming image text in transcribed
image text in transcribed
Task 1: Printing File Names using Dirent Library: (50points) Here we want to access a Linux directory using C. To do so we use the structs and functions made available in the dirent library. Below we see the function prototypes for the functions opendir, readdir, and closedir which have been implemented in the dirent library. DIR is simple type that is available from the library SYNOPSIS #include DIR *opendir ( const char *dirname ); struct dirent *readdir (DIR *dir); int closedir (DIR *dir); Dirent structure is defined as follows struct direntf ino t d ino ; /*file serial number*/ off td offoffset to the next dirent unsigned short d reclen ; /* length of this record */ unsigned char d_ type ; /* type of file */ char d_name [ 256 ] ; /*filename The following program displays the filenames contained in a directory whose pathname is passed as a command-line argument. Type in and complete the following program on the computer. Save it as shownames.c. . Compile the program as shownames.out and execute it by giving it a directory as a command ine argument. Fo example type the following nto the terminal: . /shownames.out ~/CSC4421. If you typed that then the program below will receive values of: argc-2, argv[0]"/shownames.out", argv[1]-"-/CSC4421". shownames.c

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions