This post was published long ago, when I was a student and an amateur blogger. The links might be outdated and content may not be useful anymore. Please read this content keeping its age in mind.
Subject : System Software Laboratory
Branch : Information Science & Engineering
Semester : 6
University : VTU
[Click Here to get other programs by email ]
………………………………………………………………………………………………………………………….
PART -B
………………………………………………………………………………………………………………………….
Problem Definition : C program that accepts valid file names as command line arguments and for each of the arguments, prints the type of the file (Regular file, Directory file, Character special file, Block special file, Symbolic link etc.)
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
int main(int argc,char *argv[])
{
int i;
struct stat buf;
for(i=1;i<=argc;i++)
{
printf(“%s”,argv[i]);
if(lstat(argv[i],&buf)==-1)
{
printf(“nlstat error..n”);
continue;
}
if(S_ISREG(buf.st_mode))
printf(“nRegular filen”);
else if(S_ISDIR(buf.st_mode))
printf(“nDirectory filen”);
else if(S_ISCHR(buf.st_mode))
printf(“nCharacter special filen”);
else if(S_ISBLK(buf.st_mode))
printf(“nBlock special filen”);
else if(S_ISLNK(buf.st_mode))
printf(“nSymbolic link filen”);
else
printf(“nUnknown filen”);
return 0;
}
}
Leave a ReplyCancel reply