Thread: How to print?

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    41

    Question How to print?

    Can anyone help me figure out how to print out of my programs? I have a couple programs built in c and I'd like to be able to print information from inside the programs onto paper. Can anyone tell me if this is possible? Where to get a tutorial on this? Or just tell me how the code would work?

  2. #2
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    FILE *fp
    fp = fopen("LPT1","w");
    this opens the FILE stream to the printer in port lpt1

    -Luke
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  3. #3
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    Example:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
     FILE *printer;
     printer = fopen("LPT1","w");
     fprintf(printer,"TEXT HERE");
     return 0;
    }
    make sure to have the \f escape sequence or else the printer will not no when to stop accepting input and print

    this thread has been on this board around 9 times
    perhaps it should be moved to the FAQ (Hint hint, mods)

    http://www.cprogramming.com/cboard/s...5&pagenumber=1
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Another approach:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #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( fgets(buf,BUFSIZ,fp) != NULL ) 
    	 {
      	       	fprintf(printer,"%s",buf);
    	 }
    
     	 fprintf(printer,"\f");
     	 return 0;
    }
    - Found in a matter of minutes with the search feature.
    The world is waiting. I must leave you now.

  5. #5
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    shadow, i found that also, and from you!

    thats why I posted the second code with *printer instead, I forgot it needed to be that
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. merging linked lists
    By scwizzo in forum C++ Programming
    Replies: 15
    Last Post: 09-14-2008, 05:07 PM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM
  4. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM
  5. Replies: 1
    Last Post: 07-31-2002, 11:35 AM