Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A standard Printer Routine

Status
Not open for further replies.

AmeyaPurohit

Technical User
Mar 15, 2001
3
IN
Can some of the millions of C masters out there tell me how to write a standard printer routine in C or tell me where i can find one? I would really appreciate if i get the whole code. This is for a project i am doing where we control a mobile platform connected to the printer port(LPT1) of the computer.I am not a expert C user & i am finding it very difficult. My projects stuck up due to this.
Thanks a million.
 
Not used the printer so much in 'C' but this little program works!

#include <stdio.h>
#include <string.h>

void main()
{
char s[] = &quot;hello world&quot;;
FILE *fp; /*create a pointer of the type FILE */
if((fp = fopen(&quot;PRN&quot;,&quot;w+&quot;))==NULL)/*standard file opening*/
/*display error if file cannot open*/
printf(&quot;cannot open printer&quot;);
fprintf(fp,&quot;%s&quot;,s);
fputc('\f',fp);
fclose(fp);/*close file*/
}
 
In that little snippet, it might help if you didn't write to the printer if you fail to open it in the first place :)

Writing to printers isn't covered by standard C, so how you do it depends entirely on your OS and compiler. If you posted this information, one of us might be able to help you.

Russ
bobbitts@hotmail.com
 
Yeh I agree that it depends on the OS & Compiler. I'm using
borland C++ version 5 on dos and the program that I posted works fine on that.
Ok I missed out a &quot;<stdlib.h>&quot; header file with an &quot;exit(1)&quot; command, after displaying the error.
Otherwise I reckon its OK.
 
if what you want to do is talk to an IC like
an octal/buffer line driver you can simply

outb(xxx, 0x378) OUT-->
inb(0x379) <--IN

note: xxx = the octal address of the IC's
input line.

but the preceeding is linux/unix code, for dos/windows the function is inport()/outport() but I have no Idea about the syntax or register index.

--Ian Mechura <dba@ghg.net>

--Ian Mechura
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top