Pages

Friday, 9 February 2018

Write a C program to read a large text file ‘NOTES.TXT’ and print it on the printer in cut-sheets, introducing page breaks at the end of every 50 lines and a pause message on the screen at the end of every page for the user to change the paper.



Write a C program to read a large text file ‘NOTES.TXT’ and print it on the printer in cut-sheets, introducing page breaks at the end of every 50 lines and a pause message on the screen at the end of every page for the user to change the paper.

#include<stdio.h>

#include<conio.h>

#include<string.h>



void print();



void main() {

FILE *fp;

char s[80];
int x=4,y=4,c=0,pg=0;
clrscr();

fp=fopen("NOTES.TXT","r");

if(fp==NULL) {

puts("cannot open file!");
exit();
}

while(fgets(s,74,fp)!=NULL) {

gotoxy(30,1);         /* printing page number */
printf("Page No: %3d",pg);

print(s,x,y,c);  /* function to print */

c++;
y++;

if(c>51) {           /* checking for page end */

pg++;

c=0;
gotoxy(2,24);
printf("press any key to change paper...");
getch();

clrscr();

}

if(y>22) {      /* checking for total lines */

gotoxy(2,24);
printf("press any key to go to next page...");
getch();
y=5;
clrscr();
}

}

fclose(fp);
}

void print(char *s,int x, int y, int c) {

 
   /*    page border    */


int i,bdr,bdr2;

gotoxy(1,2);
printf("%c",218);
for(bdr=3;bdr<23;bdr++) {

gotoxy(1,bdr);
printf("%c",179);

gotoxy(79,bdr);
printf("%c",179);

}

gotoxy(79,2);
printf("%c",191);

gotoxy(79,23);
printf("%c",217);

gotoxy(1,23);
printf("%c",192);

for(bdr2=2;bdr2<=78;bdr2++) {

gotoxy(bdr2,2);
printf("%c",196);

}

gotoxy(x,y);

puts(s);

if(c>50) {

for(i=2;i<79;i+=2) {

gotoxy(i,23);

printf("-");
}
}
}