Posts

Showing posts from March, 2018

Write C programs to simulate the Hierarchical directory File organization technique

Write C programs to simulate the Hierarchical  directory File organization technique #include<stdio.h> #include<graphics.h> #include<string.h> struct tree_element { char name[20]; int x, y, ftype, lx, rx, nc, level; struct tree_element *link[5]; }; typedef struct tree_element node; void main() { int gd=DETECT,gm; node *root; root=NULL; create(&root,0,"root",0,639,320); clrscr(); initgraph(&gd,&gm,"c:\tc\BGI"); display(root); closegraph(); } create(node **root,int lev,char *dname,int lx,int rx,int x) { int i, gap; if(*root==NULL) { (*root)=(node *)malloc(sizeof(node)); printf("Enter name of dir/file(under %s) : ",dname); fflush(stdin); gets((*root)->name); printf("enter 1 for Dir/2 for file :"); scanf("%d",&(*root)->ftype); (*root)->level=lev; (*root)->y=50+lev*50; (*root)->x=x; (*root)->lx=lx; (*root)->rx=rx; for(i=0;i<5;i++) (*root)->li

Write C programs to simulate the Two level directory File organization technique

Write C programs to simulate the Two level directory File organization technique #include<string.h> #include<stdlib.h> #include<stdio.h> struct { char dname[10],fname[10][10]; int fcnt; }dir[10]; void main() { int i,ch,dcnt,k; char f[30], d[30]; dcnt=0; while(1) { printf("\n\n1. Create Directory\t2. Create File\t3. Delete File"); printf("\n4. Search File\t\t5. Display\t6. Exit\tEnter your choice -- "); scanf("%d",&ch); switch(ch) { case 1: printf("\nEnter name of directory -- "); scanf("%s", dir[dcnt].dname); dir[dcnt].fcnt=0; dcnt++; printf("Directory created"); break; case 2: printf("\nEnter name of the directory -- "); scanf("%s",d); for(i=0;i<dcnt;i++) if(strcmp(d,dir[i].dname)==0) { printf("Enter name of the file -- "); scanf("%s",dir[i].fname[dir[i].fcnt]); printf("File created"); break; } if(i==dcnt) printf

Write C programs to simulate the Single level directory File organization techniqu

Write C programs to simulate the Single level directory File organization techniqu #include<stdlib.h> #include<string.h> #include<stdio.h> struct { char dname[10],fname[10][10]; int fcnt; }dir; void main() { int i,ch; char f[30]; dir.fcnt = 0; printf("\nEnter name of directory -- "); scanf("%s", dir.dname); while(1) { printf("\n\n1. Create File\t2. Delete File\t3. Search File \n 4. Display Files\t5. Exit\nEnter your choice -- "); scanf("%d",&ch); switch(ch) { case 1: printf("\nEnter the name of the file -- "); scanf("%s",dir.fname[dir.fcnt]); dir.fcnt++; break; case 2: printf("\nEnter the name of the file -- "); scanf("%s",f); for(i=0;i<dir.fcnt;i++) { if(strcmp(f, dir.fname[i])==0) { printf("File %s is deleted ",f); strcpy(dir.fname[i],dir.fname[dir.fcnt-1]); break; } } if(i==dir.fcnt) printf("File %s not found",f); else dir