#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<sys/stat.h>
#include<alloc.h>
#include<stdlib.h>
typedef struct used
{
int inode;
struct stat temp;
struct used *next;
struct time create;
struct time modi;
int lock;
int ref;
};
used *getnode()
{ used *t=(used *)malloc(sizeof(used));
t->next=NULL;
t->ref=1;
struct time temptime;
gettime(&temptime);
t->create=temptime;
return t;
}
used *fre,*start;
void init(int number)
{
used *t1,*t2,*t3;
// capacity of the inode list is 10
int i,j,k,l;
fre=getnode();
start=NULL;
t2=fre;
for(i=0;i<number;i++)
{ t1=getnode();
t2->next=t1;
t2=t1;
}
}
// max inode number will be 1000
used *cache;
void usenode();
void copy_in(used *);
void input(used *);
void display();
char loop();
void close();
int search(used *);
void incref(used *);
void main()
{
clrscr();
init(19);
char c;
int j=0;
while(1)
{ c=loop();
j=0;
if(c==13)
{ input(cache);
if(search(cache))
incref(cache);
else
usenode();
}
if(c==27)
close();
}
display();
getch();
}
char loop()
{
while(!kbhit())
{ display();
delay(1000);
clrscr();
}
char c=getch();
return c;
}
void usenode()
{
used *t,*temp;
t=fre;
if(t->next==NULL)
{
printf("No fre node avail.\n");
return ;
}
while(t->next!=NULL)
{ temp=t;
t=t->next;
}
temp->next=NULL;
// one node is deleted
t=start;
if(start==NULL)
{
start=getnode();
copy_in(start);
return ;
}
while(t->next!=NULL)
{
t=t->next;
}
temp=getnode();
copy_in(temp);
t->next=temp;
return ;
}
void copy_in(used *temp)
{
temp->inode=cache->inode;
}
void display()
{
used *t;
t=start;
int i=0;
// displaying used incore inodes
while(t!=NULL)
{ gotoxy(10,4+i);
cout<<t->inode<<":"<<t->ref;
printf(" Created on : %2d:%02d:%02d",t->create.ti_hour,t->create.ti_min,t->create.ti_sec);
t=t->next;
i++;
}
cout<<"\nUsed incore copies : "<<i<<"\n\n\n";
i=0;
// displaying fre inode list
t=fre;
while(t!=NULL)
{ t=t->next;
i++;
}
cout<<"Free incore copies : "<<i<<"\n\n\n";
}
void input(used *ch)
{ // clrscr();
int i,j,k;
cout<<"inode number : ";
cin>>ch->inode;
cout<<"\nEnter permission : ";
cin>>i;
ch->lock=i;
}
void close()
{
cout<<"Enter inode for closing file : ";
int i;
cin>>i;
used *t,*pred,*succ;
t=start;
pred=t;
int flag=0;
if(t->inode==i)
{
flag=1;
}
while(t!=NULL && t->inode!=i)
{ pred=t;
t=t->next;
if(t->inode==i)
{ flag=1;
break;
}
}
if(flag==0)
{ printf("No such found..\n");
return ;
}
if(t->ref>=1)
{ t->ref--;
}
if(t->ref!=0)
return ;
if(pred==t)
{ if(start->next!=NULL)
start=start->next;
else
start=NULL;
}
else
{
pred->next=t->next;
t->next=NULL;
}
// increments free inode list
t=fre;
while(t->next!=NULL)
{ t=t->next;
}
succ=getnode();
t->next=succ;
}
int search(used *ch)
{
used *t;
t=start;
if(t==NULL)
return 0;
int flag=0;
while(t!=NULL)
{ if(t->inode == ch->inode)
{ flag=1;
return flag;
}
t=t->next;
}
return flag;
}
void incref(used *ch)
{
used *t;
t=start;
int flag=0;
while(t!=NULL)
{ if(t->inode == ch->inode)
{ t->ref++;
break;
}
t=t->next;
}
}
c code samples for write c programs
Fibonacci numbers on c programming
i haven't got any output
It's 28 year old code posted in 2012... who even.. there are no compilers to run this
can you please share the output of this program
where can i find new version of this program
i want the updated program i can pay for that