OS - Lab10 - Dipendu Ray - 036

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

The Neotia University

OPERATING SYSTEM
LAB 10

NAME: DIPENDU RAY


UID: TNU2020020100036
DEPARTMENT: Btech CSE Cyber Security
SEMESTER-FOURTH

Marks Obtained Signature of the Sectional in charge


______________________________ ___________________________
Q-15. Write a C program to implement the single level directory structure.
CODE IN C :

#include<stdio.h>
#include<string.h>
int main()
{
int nf=0,i=0,j=0,ch;
char mdname[10],fname[10][10],name[10];

printf("Enter the directory name:");


scanf("%s",mdname);
printf("Enter the number of files:");
scanf("%d",&nf);
do
{
printf("Enter file name to be created:");
scanf("%s",name);
for(i=0;i<nf;i++)
{
if(!strcmp(name,fname[i]))
break;
}
if(i==nf)
{
strcpy(fname[j++],name);
nf++;
}
else
printf("There is already %s\n",name);
printf("Do you want to enter another file(yes - 1 or no -
0):");
scanf("%d",&ch);
}
while(ch==1);
printf("Directory name is:%s\n",mdname);
printf("Files names are:");
for(i=0;i<j;i++)
printf("\n%s",fname[i]);

}
OUTPUT :
Q-16. Write a C program to implement the multilevel directory structure.

CODE IN C :

#include<stdio.h>
struct st
{
char dname[10];
char sdname[10][10];
char fname[10][10][10];
int ds,sds[10];
}dir[10];
int main()
{
int i,j,k,n;

printf("enter number of directories:");


scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter directory %d names:",i+1);
scanf("%s",&dir[i].dname);
printf("enter size of directories:");
scanf("%d",&dir[i].ds);
for(j=0;j<dir[i].ds;j++)
{
printf("enter subdirectory name and size:");
scanf("%s",&dir[i].sdname[j]);
scanf("%d",&dir[i].sds[j]);
for(k=0;k<dir[i].sds[j];k++)
{
printf("enter file name:");
scanf("%s",&dir[i].fname[j][k]);
}
}
}
printf("\ndirname\t\tsize\tsubdirname\tsize\tfiles");
printf("\n********************\n");
for(i=0;i<n;i++)
{
printf("%s\t\t%d",dir[i].dname,dir[i].ds);
for(j=0;j<dir[i].ds;j++)
{
printf("\t%s\t\t%d\t",dir[i].sdname[j],dir[i].
sds[j]);
for(k=0;k<dir[i].sds[j];k++)
{
printf("%s\t",dir[i].fname[j][k]);
printf("\n\t\t\t\t\t\t");
}
}
printf("\n");
}

}
OUTPUT :

You might also like