Enter your email address & Win:

System Software Lab Programs ( UNIX Programs ) – 3b

// June 2nd, 2009 // Educational, Engineering, Unix and System Software Lab // Written by sandeephegde

-->

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 file\n”);

else if(S_ISDIR(buf.st_mode))
printf(“\nDirectory file\n”);

else if(S_ISCHR(buf.st_mode))
printf(“\nCharacter special file\n”);

else if(S_ISBLK(buf.st_mode))
printf(“\nBlock special file\n”);

else if(S_ISLNK(buf.st_mode))
printf(“\nSymbolic link file\n”);

else
printf(“\nUnknown file\n”);

return 0;
}
}

[Click Here to get other programs by email ]


If you enjoyed this post, make sure you subscribe to my RSS feed!

Related posts:

  1. System Software Lab Programs ( UNIX Programs ) – 6b
  2. System Software Lab Programs ( UNIX Programs ) – 5b
  3. System Software Lab Programs ( Lex and Yaac Programs )1b
  4. System Software Lab Programs ( Lex and Yaac Programs ) 3.l
  5. System Software Lab Programs ( Lex and Yaac Programs )exa
blog comments powered by Disqus
Get Adobe Flash playerPlugin by wpburn.com wordpress themes