Program to find File types

FINDING FILE TYPES USING UNIX PROGRAMS

#include
#include
#include
#include
#include
main()
{
char fname[30];
int i,ch;
struct stat buf;
do
{
printf("\n Enter the filename: \n");
scanf("%s",fname);
i=lstat(fname,&buf);

if(i==0)
{

if(S_ISREG(buf.st_mode))
printf("\n It is a Regular File");
if(S_ISDIR(buf.st_mode))
printf("\n It is a Directory File");
if(S_ISCHR(buf.st_mode))
printf("\n It is a Character File");
if (S_ISBLK(buf.st_mode))
printf("\n It is a Block File");
if(S_ISFIFO(buf.st_mode))
printf("\n It is a Fifo File");
if(S_ISLNK(buf.st_mode))
printf("\n It is a Link File");
if(S_ISSOCK(buf.st_mode))
printf("\n It is a Socket File");

}

printf(“DO YOU WANT TO CONTINUE:\n”);
scanf(“%d”,&ch);
}
while(ch!=0);
}

No comments: