Sending to printer

This is a discussion on Sending to printer within the C Programming forums, part of the General Programming Boards category; My print func() in my program isn't working properly. It asks for user input and then searches the file. When ...

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

    Sending to printer



    My print func() in my program isn't working properly. It asks for user input and then searches the file. When found, a function is called to set up the print format, then returns the format to print on printer. I tried using a separate function which is at the moment commented out. The func() seems to run all the way through because i get to key_wait, but nothing gets printed. Anybody have any ideas? The code is attached.

    Attached Files Attached Files

  2. #2
    My diaper's full....... stevey's Avatar
    Join Date
    Nov 2001
    Posts
    759
    have you tried just printing to a text file to make sure your prog is working ok ?? if so try stdprn ??

    see please help me thread for all i know about printing to printer(which isn't much)
    Steve

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    > FILE *printer = fopen("LPT1","w");
    You dont check to see if this is NULL

    And typically, to see anything printed, you have to finish off by sending a form feed

    fprintf( printer, "\f" );

    to flush the printer buffer onto the page.

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

    same prob

    Originally posted by Salem
    > FILE *printer = fopen("LPT1","w");
    You dont check to see if this is NULL

    And typically, to see anything printed, you have to finish off by sending a form feed

    fprintf( printer, "\f" );

    to flush the printer buffer onto the page.

    I tried making the changes you specified but now I'm recieving 7 errors. I don't think I have implemented these changes in the proper locations. I have tried several scenarios but still no luck. Could you take a look at the updated function and see if you know where I'm going wrong?
    Thx in advance. Peace.
    Attached Files Attached Files

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    The start of print_label
    Code:
    //!!	FILE *printer = fopen("LPT1","w");
    	FILE *printer;
    	FILE *dta_file;
    	char buf[BUFSIZ];
    	int user_inputted_client_code;
    	clrscr();
    	printf("\t\t\tClient Inventory Management \n\n\n");
    	printf("\tPrint Client Label \n\n");
    	printf("Client Code: ");
    	scanf("%d",&user_inputted_client_code);
    	if((dta_file=fopen(FILENAME,"rb")) == NULL)
    	{
    		perror(FILENAME);
    		return(1);
    	}
    //!!	if((FILE *printer = fopen("LPT1","w")) == NULL)
    	if((printer = fopen("LPT1","w")) == NULL)
    	{
    //!!		perror(LPT1);
    		perror("LPT1");
    		return (1);
    	}

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

    Thx, stupid mistakes, but mistakes none the less!
    The func() still won't print but I'm sure you already know that. My next question would be: in my while loop->
    Code:
    while( fgets(buf,BUFSIZ,dta_file) != NULL )
    {
    //	fprintf(printer,"printclient2(&another_client)",buf);
    	fprintf(printer,"buf");
    	fprintf(printer,"\f");
    }
    //fprintf(printer,"buf");
    //fprintf(printer,"\f");
    }
    The first method I tried is now commented out for the time being: am I able to call the 'printclient2' func()/ do I need to? Should the other two commented(out) lines be inside the 'while' or outside?

    Secondly I thought maybe since the structure should be found at this point, I should just use the 'fprintf' commands inside the 'while'?

    Tried both and obviously I must be missing something or my code is in the wrong places. Any more suggestions?

    The finished results I am trying to achieve, should look exactly like the screen print of the 'printclient2' func() except on paper.
    Attached Files Attached Files

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    Does it actually print anything at all?

    Also try
    int n = fprintf( printer, "buf" );
    if ( n != 3 ) {
    perror( "no dice" );
    }

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    41
    Originally posted by Salem
    Does it actually print anything at all?

    Also try
    int n = fprintf( printer, "buf" );
    if ( n != 3 ) {
    perror( "no dice" );
    }

    No, it doesn't print anything. The print controls don't show up or anything.
    Where would I put the suggested 'if' statement?

  9. #9
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Spentdome, OT question:
    Out of curiousity, why do you suddenly put everything you say in quote tags?
    The world is waiting. I must leave you now.

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Is your printer connected to the parallel, serial or USB port?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #11
    Registered User
    Join Date
    Apr 2002
    Posts
    41
    Originally posted by Shadow
    Spentdome, OT question:
    Out of curiousity, why do you suddenly put everything you say in quote tags?

    Because out of the questions I've previously asked, people kept *****'in about me not using quote or code tags. Is it a problem?

  12. #12
    Registered User
    Join Date
    Apr 2002
    Posts
    41
    Originally posted by Hammer
    Is your printer connected to the parallel, serial or USB port?

    No, I double checked that cause I thought the same thing, but it is 'LPT1".

    I can't figure out why it won't work? Do you see anything wrong with what I have? Am I missing something obvious?

    No quote tags 'Shadow', now you can relax.
    Attached Files Attached Files

  13. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    You could try approaching the problem from a different angle

    Code:
    D:\code>print /?
    Prints a text file.
    
    PRINT [/D:device] [[drive:][path]filename[...]]
    
       /D:device   Specifies a print device.
    Now the print command can be used to print a text file. Rather than changing your program, I would suggest some experiments with the print command to see if you can actually print anything.

    Something else to look at
    > if((printer = fopen("LPT1","w")) == NULL)
    Do you have a file called "LPT1" in your directory?

  14. #14
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    people kept *****'in about me not using quote or code tags. Is it a problem?
    No, not really.
    Code tags are for code.
    Quote tags are for quoting somebody.
    Bold is for stern emphasis.
    Italic is for casual emphasis.
    Caps lock is for loud emphasis.

    I don't have a problem with it, I was just curious.

    Good luck with your problem..
    The world is waiting. I must leave you now.

  15. #15
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Code:
    /*
    
    	Program:
    	Printer.c
    	
    	Purpose:
    	Demonstrates how to use the printer
    	in your programs.
    	
    */
    
    #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?\n ");
    	 scanf("%s",str);
    	 fp = fopen(str,"r");
    	 if(!fp)
    	 {
    	 	printf("File does not exist\n");
      		return -1;
     	 }
     	 while( fgets(buf,sizeof buf,fp) != NULL ) 
    	 {
    	 	printf("\nPrinting..\n");
      	       	fprintf(printer,"%s",buf);
    	 }
    
     	 fprintf(printer,"\f");
             return 0;
    }
    ....if any of that helps.
    The world is waiting. I must leave you now.

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Set Printer Prior To Loading Print Dialog Box
    By Beaner in forum Windows Programming
    Replies: 3
    Last Post: 10-10-2008, 01:02 PM
  2. changing property (layout) of a printer
    By leojose in forum Windows Programming
    Replies: 5
    Last Post: 12-05-2005, 06:16 AM
  3. Sending window to printer
    By Bazzz in forum C++ Programming
    Replies: 3
    Last Post: 07-30-2004, 09:49 AM
  4. Success - Output to Printer
    By noraa in forum C Programming
    Replies: 5
    Last Post: 08-04-2002, 09:12 AM
  5. sending data to printer port
    By lliero in forum C Programming
    Replies: 3
    Last Post: 11-20-2001, 03:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21