Indexed file access method in C.
Program :
#include<stdio.h>
int main(){
int f[50],index[50],i,st,op,ind,n_o_f,count;
for(i=0;i<50;i++)
f[i]=0;
x:
printf("Enter the index block:\n");
scanf("%d",&ind);
if(f[ind] != 1){
f[ind] = 1;
printf("Enter the # of files on index:\n");
scanf("%d",&n_o_f);
}else{
printf("Block already allocated\n");
goto x;
}
y:
count=0;
printf("\nEnter file's indexes:");
for(i=0;i<n_o_f;i++){
scanf("%d",&index[i]);
if(f[index[i]] == 0)
count++;
}
if( count == n_o_f ){
for(i=0;i<n_o_f;i++)
f[index[i]] = 1;
printf("Allocated file indexed");
for(i=0;i<n_o_f;i++)
printf("%d --> %d : %d \n",ind,index[i],f[index[i]]);
}else{
printf("\nFile in that location is already indexed\n");
goto y;
}
printf("Press 1 to continue.....\n");
scanf("%d",&op);
if(op == 1)
goto x;
return 0;
}
Output:
Enter the index block:
5
Enter the # of files on index:
1
Enter file's indexes:3
Allocated file indexed5 --> 3 : 1
Press 1 to continue.....
1
Enter the index block:
3
Block already allocated
Enter the index block:
2
Enter the # of files on index:
2
Enter file's indexes:6
7
Allocated file indexed2 --> 6 : 1
2 --> 7 : 1
Press 1 to continue.....
#include<stdio.h>
int main(){
int f[50],index[50],i,st,op,ind,n_o_f,count;
for(i=0;i<50;i++)
f[i]=0;
x:
printf("Enter the index block:\n");
scanf("%d",&ind);
if(f[ind] != 1){
f[ind] = 1;
printf("Enter the # of files on index:\n");
scanf("%d",&n_o_f);
}else{
printf("Block already allocated\n");
goto x;
}
y:
count=0;
printf("\nEnter file's indexes:");
for(i=0;i<n_o_f;i++){
scanf("%d",&index[i]);
if(f[index[i]] == 0)
count++;
}
if( count == n_o_f ){
for(i=0;i<n_o_f;i++)
f[index[i]] = 1;
printf("Allocated file indexed");
for(i=0;i<n_o_f;i++)
printf("%d --> %d : %d \n",ind,index[i],f[index[i]]);
}else{
printf("\nFile in that location is already indexed\n");
goto y;
}
printf("Press 1 to continue.....\n");
scanf("%d",&op);
if(op == 1)
goto x;
return 0;
}
Output:
Enter the index block:
5
Enter the # of files on index:
1
Enter file's indexes:3
Allocated file indexed5 --> 3 : 1
Press 1 to continue.....
1
Enter the index block:
3
Block already allocated
Enter the index block:
2
Enter the # of files on index:
2
Enter file's indexes:6
7
Allocated file indexed2 --> 6 : 1
2 --> 7 : 1
Press 1 to continue.....
3
Comments
Post a Comment