IMPLMENTATION OF LINUX SYSTEM CALLS
[opendir (),readdir(),closedir()]
AIM:
To write a C program to access directories using LINUX system calls
opendir (),readdir(),closedir().
ALGORITHM:
- Start the process.
- Create a directory entry in the dirent structure and a directory variable
- Get the name of the directory to be opened
- Using the system call opendir(),open the given directory and store it in the directory variable.
- Read the contents of the directory using readdir()system call and print the list of files in the directory
- Close the directory after the read and write process
- Stop the process.
PROGRAM:
#include<Stdio.h>
#include<dirent.h>
Struct dirent *dptr;
int main(int argc,char *argv[])
{
char buff[256];
DIR *dirp;
printf(“\n \n enter directory name”);
scanf(“%s”,buff);
if ((disp=opendir(buff))==null);
{
printf(“error”);
exit(1);
} while (dptr=readir(disp))
{
printf(“%s\n”,dptr->d_name);
}
closedir(dirp);
}
OUTPUT:
Enter directory name raju
Ashwini.c
maha.c
RESULT:
Thus the given C Program is executed and output is verified.
0 comments:
Post a Comment