Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *printer = fopen("LPT1","w");
FILE *fp;
char str[256];
char buf[BUFSIZ];
printf("File name? ");
scanf("%s",str);
fp = fopen(str,"r");
if(!fp)
{
printf("File does not exist\n");
return -1;
}
fgets(buf,BUFSIZ,fp);
while(buf[0])
{
fprintf(printer,"%s",buf);
fgets(buf,BUFSIZ,fp);
}
fprintf(printer,"\f");
return 0;
}
This code was originally posted by someone I don't remember .
The code was reworked by Prelude into this:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *printer = fopen("LPT1","w");
FILE *fp;
char str[256];
char buf[BUFSIZ];
printf("File name? ");
scanf("%s",str);
fp = fopen(str,"r");
if(!fp)
{
printf("File does not exist\n");
return -1;
}
fgets(buf,sizeof buf,fp);
while(buf[0])
{
fprintf(printer,"%s",buf);
fgets(buf,sizeof buf,fp);
}
fprintf(printer,"\f");
return 0;
}
I used the source code for this file as a printing test ( as it resides in the same directory, hopefully ). The printer prints your file just fine. However, it then dives into an endless loop of right code braces.
> char buf[BUFSIZ];
Do I need to change the BUFSIZ into sizeof buf to match Prelude's change?