Program-8
Program-8
#include<stdio.h>
#include<string.h>
struct file
{
char filename[20];
};
int main()
{
struct file dir[50];
int n, i;
#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: