c program which accept one argument as a directory name and
prints all the file name along with its inode number and
total count of the file in directory

Answer Posted / rakesh

#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <stddef.h>
#include <sys/stat.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
DIR *dip;
struct dirent *dit;
struct stat sb;
int i = 0;
if(argc < 2)
{
printf("Usage: %s <directory>\n", argv[0]);
return 0;
}
if((dip = opendir(argv[1])) == NULL)
{
perror("opendir");
return 0;
}
printf("Directory stream is now open\n");
while ((dit = readdir(dip)) != NULL)
{
i++;
stat(dit->d_name,&sb);
printf("%u \t%s\n",sb.st_ino,dit->d_name);
}
printf("No. of Files in directory are: %i \n", i);
if(closedir(dip)== -1)
{
perror("closedir");
return 0;
}
printf("\nDirectory stream is now closed\n");
return 1;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Using set -A write a script to print the output of the ls command in 5 columns with two spaces between each column. Pretend that ls does not have multicolumn output.

2027


What is the purpose of scripting?

568


How do I run a powershell script?

565


What is shell variable?

523


Calculate a real number calculation directly from the terminal and not any shell script.

648






What is a shell script? Can you name some of its advantages?

522


Explain about login shell?

629


How will you emulate wc –l using awk?

902


What is mac default shell?

609


What does $1 mean in bash?

610


What does $0 mean in shell script?

550


What is web script?

575


what is info area how many types?

2281


Why is it called a shell?

499


How to print pid of the current shell?

595