Solved

DOS C sending to printer in Visual C++

Posted on 1997-04-21
7
364 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
Comment Utility
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
Comment Utility
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
Comment Utility
Adjusted points to 30
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Expert Comment

by:RONSLOW
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

743 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

18 Experts available now in Live!

Get 1:1 Help Now