program for TO COUNT THE NO OF BLANKS IN TEXT FILE USING STANDARD I/O AND SYSTEM CALLS using c-languge


TO COUNT THE NO OF BLANKS IN TEXT FILE USING STANDARD I/O AND SYSTEM CALLS

#include<stdio.h>
#include<conio.h>
void main()
{
char c;
int count=0;
FILE *f1;
f1=fopen("hai.txt","w");
printf("\nEnter text & press ctrl z at the end\n");
while((c=getchar())!=EOF)
{
putc(c,f1);
}
fclose(f1);
f1=fopen("hai.txt","r");
while((c=getc(f1))!=EOF)
{
if(c==' ')
count++;
}
fclose(f1);
printf("\nThe no of blank spaces in the text are %d", count);        }

program for TO MAKE A COPY OF FILE USING STANDARD I/O AND SYSTEM CALLS using c-languge


TO MAKE A COPY OF FILE USING STANDARD I/O AND SYSTEM CALLS

#include<stdio.h>
#include<conio.h>
void main()
{
char c;
FILE *f1,*f2;
f1=fopen("hai.txt","w");
printf("\nEnter text & press ctrl+z at the end\n");
while((c=getchar())!=EOF)
putc(c,f1);
fclose(f1);
printf("\nThe contents of file are\n");
f1=fopen("hai.txt","r");
while((c=getc(f1))!=EOF)
putchar(c);
fclose(f1);
printf("\nThe contents of second file  that are copy from first file are\n");
f2=fopen("hai.txt","r");
while((c=getc(f2))!=EOF)
putchar(c);
fclose(f2);
}

program for PAGING TECHNIC OF MEMORY MANAGEMENT using c-languge


PAGING TECHNIC OF MEMORY MANAGEMENT
#include<stdio.h>
#define MAX 50
int main()
{
int page[MAX],i,n,f,ps,off,pno;
clrscr();
printf("\nEnter the no of pages in memory");
scanf("%d",&n);
printf("\nEnter page size");
scanf("%d",&ps);
printf("\nEnter no of frames");
scanf("%d",&f);
for(i=0;i<n;i++)
page[i]=-1;
printf("\nEnter the page table\n");
printf("(Enter frame no as -1 if that page is not present in any frame)\n\n");
printf("\npageno\tframeno\n-------\t-------");
for(i=0;i<n;i++)
{
printf("\n\n%d\t\t",i);
scanf("%d",&page[i]);
}
printf("\n\nEnter the logical address(i.e,page no & offset):");
scanf("%d%d",&pno,&off);
if(page[pno]==-1)
printf("\n\nThe required page is not available in any of frames");
else
printf("\n\nPhysical address(i.e,frame no & offset):%d,%d",page[pno],off);
getch();
return 1;
}

program for LFU AGORITHM using c-languge


LFU ALGORITHM
#include<stdio.h>
int n;
main()
{
int seq[30],fr[5],pos[5],find,flag,max,i,j,m,k,t,s,pf=0;
int count=1,p=0;
float pfr;
clrscr();
printf("enter max limit of the sequence:");
scanf("%d",&max);
printf("enter the sequence:");
for(i=0;i<max;i++)
  scanf("%d",&seq[i]);
printf("enter the no of frames:");
scanf("%d",&n);
fr[0]=seq[0];
pf++;
printf("%d\t",fr[0]);
i=1;
while(count<n)
{
flag=1;
p++;
for(j=0;j<i;j++)
{
if(seq[i]==seq[j])
flag=0;
}
if(flag!=0)
{
fr[count]=seq[i];
printf("%d\t",fr[count] );
count++;
pf++;
}
i++;
}
printf("\n");
for(i=p;i<max;i++)
{
flag=1;
for(j=0;j<n;j++)
{
if(seq[i]==fr[j])
flag=0;
}
if(flag!=0)
{
for(j=0;j<n;j++)
{
m=fr[j];
for(k=i;k<max;k++)
{
if(seq[k]==m)
{
pos[j]=k;
break;
}
else
pos[j]=-1;
}
}
for(k=0;k<n;k++)
{
if(pos[k]==-1)
flag=0;
}
if(flag!=0)
s=findmax(pos);
if(flag==0)
{
for(k=0;k<n;k++)
{
if(pos[k]==-1)
{
s=k;
break;
}
}
}
pf++;
fr[s]=seq[i];
for(k=0;k<n;k++)
printf("%d\t",fr[k]);
printf("\n");

}
}
pfr=(float)pf/(float)max;
printf("\n theno of page faults are:%d",pf);
printf("\n page fault rate:%f",pfr);
getch();
}
int findmax(int a[])
{
int max,i,k=0;
max=a[0];
for(i=0;i<n;i++)
{
if(max<a[i])
{
max=a[i];
k=i;
}
}
return k;
}


program for LRU AGORITHM using c-languge


LRU ALGORITHM
#include<stdio.h>
int f[30],fs;
int cnt[30];
int flag,ps[30];
main()
{
int p,i,pos=0,j,k,max,s,pf=0;
float pfr;
void increment();
int check();
clrscr();
printf("enter no of pages:");
scanf("%d",&p);
printf("enter the pages:");
for(i=0;i<p;i++)
scanf("%d",&ps[i]);
printf("enter the frame size:");
scanf("%d",&fs);
for(k=0;k<fs;k++)
 f[k]=-999;
 for(i=0,j=0;i<p;i++)
 {
 flag=0;
 if(f[i]==-999)
 {
 check(j,ps[j]);
 if(flag==0)
 {
 f[j]=ps[i];
 pf++;
 for(k=0;k<=j;k++)
 cnt[k]+=1;
 j++;
 }
 }
 else
 {
 check(fs,ps[i]);
 if(flag==0)
 {
 max=cnt[0],pos=0;
 for(k=1;k<fs;k++)
 if(max<cnt[k])
 max=cnt[k],pos=k;
 f[pos]=ps[i],pf++;
 increment(ps[i]);
 }
 }
 for(k=0;k<fs;k++)
 printf("%4d",f[k]);
 printf("\n");
 }
 pfr=(float)pf/p;
 printf("total no of page faults:%d\n",pf);
 printf("page fault rare:%f",pfr);
 getch();
 }
 void increment(int ele)
 {
 int k;
 for(k=0;k<fs;k++)
 {
 if(f[k]==ele)
 cnt[k]=1;
 else
 cnt[k]+=1;
 }
 }
 check(int pos,int ele)
 {
 int k,s;
 for(k=0;k<fs;k++)
 if(f[k]==ele)
 {
 cnt[k]=1;
 for(s=0;s<pos;s++)
 if(s!=k)
 cnt[s]+=1;
 flag=1;
 }
 }