0% found this document useful (0 votes)
13 views3 pages

Program 8

Uploaded by

mohammeduzair044
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Program 8

Uploaded by

mohammeduzair044
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program 8 : Simulate following File Organization Techniques a) Single level

directory b) Two level directory

a) Single level directory

#include<stdio.h>
#include<string.h>
struct file
{
char filename[20];
};
int main()
{
struct file dir[50];
int n, i;

printf("Enter the number of files: ");


scanf("%d", &n);

printf("Enter the names of files:\n");


for(i = 0; i < n; i++)
{
scanf("%s", dir[i].filename);
}
printf("\nFiles in the directory:\n");
for(i = 0; i < n; i++)
{
printf("%s\n", dir[i].filename);
}
return 0;
}
b) Two level directory

#include<stdio.h>
#include<string.h>
struct directory
{
char dirname[20];
struct file
{
char filename[20];
} files[50];
int num_files;
};
int main()
{
struct directory dir[50];
int n, i, j;
printf("Enter the number of directories: ");
scanf("%d", &n);
for(i = 0; i < n; i++)
{
printf("Enter the name of directory %d: ", i+1);
scanf("%s", dir[i].dirname);
printf("Enter the number of files in directory %s: ", dir[i].dirname);
scanf("%d", &dir[i].num_files);
printf("Enter the names of files in directory %s:\n", dir[i].dirname);
for(j = 0; j < dir[i].num_files; j++) {
scanf("%s", dir[i].files[j].filename);
}
}
printf("\nDirectories and Files:\n");
for(i = 0; i < n; i++)
{
printf("Directory: %s\n", dir[i].dirname);
printf("Files:\n");
for(j = 0; j < dir[i].num_files; j++)
{
printf("\t%s\n", dir[i].files[j].filename);
}
}
return 0;
}
Output:

You might also like