#include<stdio.h>
#include<sys/stat.h>
#include<sys/types.h>
main(int argc,char *argv[])
{
int i;
struct stat statbuf;
char *ptr;
for(i=0;i<argc;i++)
{
printf("the file%s is",argv[i]);
if(stat(argv[i],&statbuf)<0)
{
printf("f staterror");
exit(1);
}
switch(statbuf.st_mode &S_IFMT)
{
case S_IFDIR:ptr="directory";
break;
case S_IFCHR:ptr="character special";
break;
case S_IFREG:ptr="regular";
break;
case S_IFBLK:ptr="block special";
break;
case S_IFIFO:ptr="fifo";
break;
default:ptr="unknown mode";
break;
}
printf("%s \n",ptr);
}
exit(0);
}
OUTPUT
./a.out f1 file.c
file f1 is REGULAR
file file.c is REGULAR
No comments:
Post a Comment