[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

DOS C sending to printer in Visual C++

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
direwolf
Asked:
direwolf
  • 4
  • 3
1 Solution
 
RONSLOWCommented:
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
 
direwolfAuthor Commented:
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
 
direwolfAuthor Commented:
Adjusted points to 30
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
RONSLOWCommented:
Have you captured your printer .. perhaps PRN only works when a printer is caputred (check your printer properties)
0
 
RONSLOWCommented:
Note: that the "str" referred to in the assert if your "stream" variable - ie. your fopen failed.
0
 
RONSLOWCommented:
Try capturing your printer as LPT1 first.No try opening LPT1 in your program.Don't forget to check for a successful open.
0
 
direwolfAuthor Commented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now