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 / 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 |
What happens when you type ls?
What is a scripting language simple definition?
What is awk in shell script?
What are the three main forms of enabling debugging in a shell script?
how did u debugging in unix/ linux platform ??( project Related)
How to customise the other shell?
how to separate the even and odd number generated from one file to two separate file i.e. even numbers in file1.txt and odd numbers in file2.txt
How to create environment variables?What are the conditions for creating variables?
Why are there shells on the beach?
is this growing field and what is average package in this?
what is this line in the shell script do ?#!/bin/ksh
Explain about debugging?