Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7554131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:15:21+00:00 2026-05-30T11:15:21+00:00

I know how to simply print a text file to the printer: (See my

  • 0

I know how to simply print a text file to the printer:
(See my question below the code block)

#include <stdio.h>
#include <stdlib.h>

int main ( void )
{
     FILE * Printer = fopen("LPT1", "w");
     FILE * FilePointer;
     char str[256];
     char buf[BUFSIZ];
     FilePointer = fopen("sample.txt", "r");
     if( !FilePointer )
     {
        printf("File does not exist\n");
        return -1;
     }
     while( fgets ( buf, sizeof buf, FilePointer ) != NULL ) 
     {
            fprintf(Printer, "%s", buf);
     }
         printf("\nPrinting..\n");
     fprintf(Printer, "\f");

     getch(); 
     return 0;
}

But my problem is for error catching when using this technique to print a text to printer.
What if the user has no valid or usable printer at that time? I want my program to spit out something like: “Error: printer does not exist!”.

Is there anything I could do with that? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:15:23+00:00Added an answer on May 30, 2026 at 11:15 am

    You can check if the printer is online, but only if you have access to kernel mode, if you are a printing driver or under Windows 95/98.

    Usually, the printer port address is set 0x378 (data register of parallel port). Adding one (0x379) to this gives us the address of the status register of the parallel port. bit 4 of the status register (SELECT) tells us whether the printer is online or offline. if the bit is set, then the printer is online
    and if its 0, the bit is offline.
    It can look like this :

    int status;
    
    // get status register value at 0x379
    status = _inp (0x379);
    
    if (status & 0x10) // check bit 4
    {
    // printer online
    }
    else
    {
    // printer offline
    } 
    

    Here are the other member of this register :

     bit 1 : DCN
     bit 3 : FAULT
     bit 4 : SELECT
     bit 5 : PAPER END
     bit 6 : ACKNOWLEDGE
     bit 7 : BUSY
    

    It’s coming from codeguru. But take note you should better use a higher interface like the printer api in WIN32 (OpenPrinter(), WritePrinter() StarDocPrinter(), StartPagePrinter(), etc.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <stdio.h> #include <stdlib.h> #include <string.h> char *readLine(FILE *inFile) //Simply reads line in a
C code: #include <stdio.h> main() { int i; for (i = 0; i <
Does anyone know how to write to a text file in Android using a
import sys, os X = os.system(ipconfig) print X 0 I know its simple, I'm
I know that you cannot simply set DocumentRoot in htaccess but it's all I
I would simply like to know if it is possible to load tumblr posts
I know I should do my homework on my own but I simply can't
Does anyone know of a way to simply and effectively brighten a UIImage by
I don't know what I'm not doing but I simply cannot get my own
So I know I can convert a string to a hashcode simply by doing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.