Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

program won't detect printer

doyliedoylie Member Posts: 50
#include
#include

FILE *fp;

void main()
{
if ((fp = fopen("LPT1:","w"))==NULL)
{
printf("Printer not on line - please check
");
exit(1);
}

fprintf(fp,"Andrew Doyle
");

fprintf(fp,"%43s
","DOB: 05/10/75");

}

This program won't detect my printer does anyone know why?

Comments

  • SteveCSteveC Member Posts: 63
    See
    http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=3&MsgID=143851&Setting=A9999F0002

    Are you running DOS (not win32 console in 9x/NT/2K/XP), and compiling this with a DOS compiler (not VC++ / Dev-C++ / DJGPP or any other 32 bit compiler), and have a printer plugged into the parallel port?

    If the answer is 'no' to any of those, we need more detail about the environment. You have written a classic DOS program for writing ASCII text to a printer.

    And main returns int, not void

    : #include
    : #include
    :
    : FILE *fp;
    :
    : void main()
    : {
    : if ((fp = fopen("LPT1:","w"))==NULL)
    : {
    : printf("Printer not on line - please check
    ");
    Add this line
    perror( "The error is" );


    : exit(1);
    : }
    :
    : fprintf(fp,"Andrew Doyle
    ");
    :
    : fprintf(fp,"%43s
    ","DOB: 05/10/75");
    :
    : }
    :
    : This program won't detect my printer does anyone know why?
    :

  • JackPackJackPack Member Posts: 7
    : #include
    : #include
    :
    : FILE *fp;
    :
    : void main()
    : {
    : if ((fp = fopen("LPT1:","w"))==NULL)
    : {
    : printf("Printer not on line - please check
    ");
    : exit(1);
    : }
    :
    : fprintf(fp,"Andrew Doyle
    ");
    :
    : fprintf(fp,"%43s
    ","DOB: 05/10/75");
    :
    : }
    :
    : This program won't detect my printer does anyone know why?
    :

    hi there,
    well, listen - maybe there is a way to print with fopen(), but i
    don't never heard of such way.
    i made couple a days ago a printing function based on bios.h
    you might wanna try.

    the function receives a string to output and print it (you can change
    LPT1 to LPT2 inside the function).
    there it is:

    #include

    #define LPT1 0
    #define LPT2 1

    /* Print a string unsing a printer LPT1 */
    /* Automatic line hendling (
    ) according to string */
    /* 78 chars in each line, 66 lines */
    void str_printer(char str[])
    {
    unsigned i, abyte='
    ';
    int c=0;

    _bios_printer(_PRINTER_INIT,LPT1,abyte);
    _bios_printer(_PRINTER_WRITE, LPT1, abyte);
    for (i=0; str[i]!=''; i++)
    {
    if (str[i]=='
    ')
    {
    _bios_printer(_PRINTER_WRITE, LPT1, '
    ');
    c=0;
    }
    else
    {
    c++;
    if (c>=79)
    {
    c=0;
    _bios_printer(_PRINTER_WRITE, LPT1, '
    ');
    _bios_printer(_PRINTER_WRITE, LPT1, '
    ');
    }
    }
    abyte=str[i];
    _bios_printer(_PRINTER_WRITE, LPT1, abyte);
    }
    }

    i tried it on my old hp694c and i had no problems.
    i hope i've been helpful.
  • doyliedoylie Member Posts: 50
    : See
    : http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=3&MsgID=143851&Setting=A9999F0002
    :
    : Are you running DOS (not win32 console in 9x/NT/2K/XP), and compiling this with a DOS compiler (not VC++ / Dev-C++ / DJGPP or any other 32 bit compiler), and have a printer plugged into the parallel port?
    :
    : If the answer is 'no' to any of those, we need more detail about the environment. You have written a classic DOS program for writing ASCII text to a printer.
    :
    : And main returns int, not void
    :
    : : #include
    : : #include
    : :
    : : FILE *fp;
    : :
    : : void main()
    : : {
    : : if ((fp = fopen("LPT1:","w"))==NULL)
    : : {
    : : printf("Printer not on line - please check
    ");
    : Add this line
    : perror( "The error is" );
    :
    :
    : : exit(1);
    : : }
    : :
    : : fprintf(fp,"Andrew Doyle
    ");
    : :
    : : fprintf(fp,"%43s
    ","DOB: 05/10/75");
    : :
    : : }
    : :
    : : This program won't detect my printer does anyone know why?
    : :
    :
    :
    I am using Borland C++ 4.5 in windows 98. My printer is plugged into parrallel port. Also why does main return int?

  • Andre YoungAndre Young USAMember Posts: 0

    _____ { http://forcoder.org } free video tutorials and ebooks about { C# Assembly Perl Go Swift Java Scratch MATLAB R C++ PL/SQL Delphi JavaScript Python Visual Basic .NET Objective-C Ruby PHP Visual Basic C SAS Hack F# Lua Scala VBScript Clojure Lisp LabVIEW Prolog ABAP COBOL Rust Transact-SQL Dart ML Awk Kotlin Erlang Apex Scheme Julia Alice Fortran Logo D Ada Bash Crystal FoxPro } _________

Sign In or Register to comment.