I was wondering how i could print out a file, like send document1.txt to the printer in c++
if anyone can help me thanks
I was wondering how i could print out a file, like send document1.txt to the printer in c++
if anyone can help me thanks
Try this to start:
-PreludeCode:file *printer = fopen ( "LPT1", "w" ); . . . fprintf ( printer, "%s\f", string );
My best code is written with the delete key.
It'd probably be like
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); // this may not be the correct syntax while(buf[0]) { fprintf(printer,"%s",buf); fgets(buf,BUFSIZ,fp); // this may not be the correct syntax } fprintf(printer,"\f"); return 0; }
>fgets(buf,BUFSIZ,fp); // this may not be the correct syntax
It is, but what if the size of buf is changed? You don't want to go through the program changing every fgets call, this works better:
fgets ( buf, sizeof buf, fp );
-Prelude
My best code is written with the delete key.
Why does everyone use the C style streams instead of C++, is it better than fstream?
I tried this code. It seems to have an infinte loop. The program created a huge file to the printer that kept printing the last part of the file.