Skip to main content

File Allocation Programs

Linked File allocation

#include<stdio.h>
#include<conio.h>

struct fileTable

{
char name[20];

int nob;

struct block *sb;
}ft[30];

struct block

{
int bno;

struct block *next;

};

void main()

{

int i, j, n;
char s[20];

struct block *temp;



printf("Enter no of files   :");
scanf("%d",&n);

for(i=0;i<n;i++)

{

printf("\nEnter file name %d :",i+1);
scanf("%s",ft[i].name);
printf("Enter no of blocks in file %d :",i+1); scanf("%d",&ft[i].nob);

ft[i].sb=(struct block*)malloc(sizeof(struct block)); temp = ft[i].sb;

printf("Enter the blocks of the file :"); scanf("%d",&temp->bno); temp->next=NULL;

for(j=1;j<ft[i].nob;j++)

{

temp->next = (struct block*)malloc(sizeof(struct block)); temp = temp->next;

scanf("%d",&temp->bno);
}

temp->next = NULL;

}

printf("\nEnter the file name to be searched -- "); scanf("%s",s);

for(i=0;i<n;i++)

if(strcmp(s, ft[i].name)==0) break;
if(i==n)

printf("\nFile Not Found");

else
{

printf("\nFILE NAME NO OF BLOCKS BLOCKS OCCUPIED"); printf("\n %s\t\t%d\t",ft[i].name,ft[i].nob); temp=ft[i].sb;

for(j=0;j<ft[i].nob;j++)

{

printf("%d à ",temp->bno); temp = temp->next;

}

}

getch();
}

Output



Indexed File Allocation

#include<stdio.h>

#include<conio.h>

struct fileTable

{

char name[20];
int nob, blocks[30];

}ft[30];

void main()

{

int i, j, n; char s[20]; 

printf("Enter no of files :"); scanf("%d",&n); for(i=0;i<n;i++)
{

printf("\nEnter file name %d :",i+1); scanf("%s",ft[i].name);

printf("Enter no of blocks in file %d :",i+1); scanf("%d",&ft[i].nob);

printf("Enter the blocks of the file :"); for(j=0;j<ft[i].nob;j++)
scanf("%d",&ft[i].blocks[j]);

}

printf("\nEnter the file name to be searched -- "); scanf("%s",s);

for(i=0;i<n;i++)

if(strcmp(s, ft[i].name)==0) break;

if(i==n)

printf("\nFile Not Found");

else
{

printf("\nFILE NAME NO OF BLOCKS BLOCKS OCCUPIED"); printf("\n %s\t\t%d\t",ft[i].name,ft[i].nob); for(j=0;j<ft[i].nob;j++)

printf("%d, ",ft[i].blocks[j]);

}

getch();
}



Comments

Popular posts from this blog

Bit Stuffing Program

#include<stdio.h> main() { int i,j,k,n,count=0; int a[30],b[30]; printf("The flag is 01111110"); printf("\n Enter the message size:"); scanf("%d",&n); printf("\n Enter the message in bits(0/1):"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("\n The message is:"); for(i=0;i<n;i++) { printf("%d",a[i]); } printf("\n"); for(i=0,j=0;i<n;i++,j++) { if(a[i]==1) { if(count==5) { b[j]=0; j++; count=0; } else count++; b[j]=a[i]; } k=j; printf("\n The coded message is:"); printf("01111110 /t"); for(j=0;j<k;j++) { printf("%d",b[j]); } printf("\01111110\n"); count=0; printf("The encoded message is :\n"); printf("\n 01111110 \t"); for(i=0;i<k;i++) { if(b[i]==1 && count<5) { printf("%d",b[i]...

CPU Schedueling programs

        Fcfs program         #include<stdio.h> #include<conio.h> main() { int bt[20], wt[20], tat[20], i, n; float wtavg, tatavg; printf("\nEnter the number of processes -- "); scanf("%d", &n); for(i=0;i<n;i++) { printf("\nEnter Burst Time for Process %d -- ", i); scanf("%d", &bt[i]); } wt[0] = wtavg = 0; tat[0] = tatavg = bt[0]; for(i=1;i<n;i++) { wt[i] = wt[i-1] +bt[i-1]; tat[i] = tat[i-1] +bt[i]; wtavg = wtavg + wt[i]; tatavg = tatavg + tat[i]; } printf("\t PROCESS \tBURST TIME \t WAITING TIME\t TURNAROUND TIME\n"); for(i=0;i<n;i++) printf("\n\t P%d \t\t %d \t\t %d \t\t %d", i, bt[i], wt[i], tat[i]); printf("\nAverage Waiting Time -- %f", wtavg/n); printf("\nAverage Turnaround Time -- %f", tatavg/n); getch(); } Output SJF program #include<stdio.h> #include<conio.h> main() { int p[20], bt[20], wt[20],...