Solved

DOS C sending to printer in Visual C++

Posted on 1997-04-21
7
366 Views
Last Modified: 2013-12-14
I need help programming in Visual C++ std 4.0 for win 95.  I'm using the C language, and I need to know how to send text to the printer.  fprintf(stdprn,...) doesn't work.  Is there any other way I can get my txt to the printer.  NOTE: I need to be able to send variables with the text as well... thanx.  Let me know if you'd like to see my source code... well the general format of each of my statements is

fprintf(stdprn, "Message!  [Variable: %d]", [aVar]);

Thanx
Direwolf
direwolf@emapnet.com
0
Comment
Question by:direwolf
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1250049
Here is your answer straight from VC help...  
PSS ID Number: Q23976
Article last modified on 11-07-1995
 
5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50 | 1.00 2.00 2.10 4.00
 
MS-DOS                      | WINDOWS   | WINDOWS NT
 

 
----------------------------------------------------------------------
The information in this article applies to:
 
 - Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax
 - Microsoft C/C++ for MS-DOS, version 7.0
 - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
 - Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, and 4.0
----------------------------------------------------------------------
 
SUMMARY
=======
 
This article presents three methods an application can use to send
output to a printer.
 
MORE INFORMATION
================
 
Method 1
--------
 
The first method uses the fprintf() function with the preopened
"stdprn" stream. The following code example demonstrates this
technique:
 
   #include <stdio.h>
   main()
   {
      fprintf(stdprn, "a line of text\n");
   }
 
This method works only in the MS-DOS operating system because the
"stdprn" stream is not defined by Microsoft Windows or Microsoft
Windows NT.
 
Method 2
--------
 
Another method uses the fopen() function to open the LPT1, LPT2, or
PRN device as a file and uses the fprintf() function to write data to
the file handle returned by fopen(). The following code example
demonstrates this technique:
 
   #include <stdio.h>
   main()
   {
      FILE *stream;
 
      stream = fopen("PRN", "w");
      fprintf(stream, "a line of text\n");
   }
 
This method works in Windows NT as well as the MS-DOS and Windows operating
systems.
 
Method 3
--------
 
Finally, in MS-DOS, an application can use the int86() or int86x()
functions to call one of the following BIOS printer services provided
by Interrupt 17h:
 
   service 0: send byte to the printer.
   service 1: initialize the printer.
   service 2: get printer status.
 
REFERENCES
==========
 
For more information on the int86() and int86x() functions, refer to
the Microsoft C "Run-Time Library Reference" manual.
 
Additional reference words: kbinf 1.00 1.50 2.00 2.10 4.00 5.10 6.00 6.00a
6.00ax 7.00
KBCategory: kbprg kbfasttip
KBSubCategory: CLngIss
=============================================================================
Copyright Microsoft Corporation 1995.

0
 

Author Comment

by:direwolf
ID: 1250050
Perhaps I should give you my source code, because this is not working.  Though I will give you credit, at least it will compile.  Here's my code:

// structure of the output variable

struct tgChr {
      char name[31];
      int fi;
      int dx;
      int in;
      int ju;
      int ps;
      int ch; };

// Code of program...

void printCharacter()
{
      FILE *stream;
      puts("Get Ready to Print\nPress Return to Print");
      fflush(stdin);
      getchar();
      fflush(stdin);
      puts("Printing Character...");
      stream = fopen("PRN", "w");
      fprintf(stream, "The Game Character\n");
      fprintf(stream, "File created with The Game Character Generater\n");
      fprintf(stream, "VERSION for DOS.\n");
      fprintf(stream, "by Andrew Gould\n");
      fprintf(stream, "Name: \t\t%s\n", curChar.name);
      fprintf(stream, "Fitness: \t%d\n", curChar.fi);
      fprintf(stream, "Dexterity: \t%d\n", curChar.dx);
      fprintf(stream, "Intelligence:\t%d\n", curChar.in);
      fprintf(stream, "Judgement:\t%d\n", curChar.ju);
      fprintf(stream, "Psyche:\t\t%d\n", curChar.ps);
      fprintf(stream, "Charisma:\t%d\n", curChar.ch);
      puts("Printing competed.");
}

My variables are all there... the point where this fails in frpintf.c is _ASSERT(str != NULL) [line 56]

Perhaps you can figure it out now?  Your other answer did not work...
0
 

Author Comment

by:direwolf
ID: 1250051
Adjusted points to 30
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Expert Comment

by:RONSLOW
ID: 1250052
Have you captured your printer .. perhaps PRN only works when a printer is caputred (check your printer properties)
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1250053
Note: that the "str" referred to in the assert if your "stream" variable - ie. your fopen failed.
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 30 total points
ID: 1250054
Try capturing your printer as LPT1 first.No try opening LPT1 in your program.Don't forget to check for a successful open.
0
 

Author Comment

by:direwolf
ID: 1250055
It worked... here's the syntax:

FILE * printer;
printer = fopen("LPT1", "a"); // or LPT2
fprint(printer, "TEXT [%conversion...]"[, aVar[,...]]);
fclose(printer);

Thanx for your help...
Direwolf
direwolf@emapnet.com
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now