Opening and page wise viewing of a file using c program :
This post is about page wise printing a file on console using
file input and output. When we print file from disk on console so it will break
it into parts specified by us using the following code just use a counter and increase
its value and use an if condition to reach at that particular position , from
where we want to break that page into parts .The number of lines in a file can vary
you can adjust according to your need.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int m=0;
char c;
FILE *fp;
clrscr();
fp=fopen("c:avg_dma.c","r");
if(fp==NULL)
{
printf("File Opening error");
exit(0);
}
else
while(1)
{
c=fgetc(fp);
if(c==EOF)
break;
else
if(m== 132) /*here the number given 132 can vary according to your need you can set it by increasing and decreasing it/
getch();
putc(c,stdout);
m++;
}
getch();
}
Comments
Post a Comment