Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a C++ Expert!

Join 244,304 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 772 people online right now. Registration is fast and FREE... Join Now!




need codes for hardcopy output using c language

 
Reply to this topicStart new topic

need codes for hardcopy output using c language

mohit333
7 Jan, 2009 - 11:33 PM
Post #1

New D.I.C Head
*

Joined: 7 Jan, 2009
Posts: 1

i need to know how to send output to printer using c language
need codes for hardcopy output using c language
i need help?

User is offlineProfile CardPM
+Quote Post


no2pencil
RE: Need Codes For Hardcopy Output Using C Language
7 Jan, 2009 - 11:33 PM
Post #2

Unix Ronin
Group Icon

Joined: 10 May, 2007
Posts: 10,438



Thanked: 198 times
Dream Kudos: 2725
Expert In: Goofing Off

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
User is offlineProfile CardPM
+Quote Post

badjava
RE: Need Codes For Hardcopy Output Using C Language
8 Jan, 2009 - 12:12 AM
Post #3

D.I.C Regular
Group Icon

Joined: 29 Oct, 2008
Posts: 482



Thanked: 7 times
Dream Kudos: 25
My Contributions
QUOTE(mohit333 @ 7 Jan, 2009 - 11:33 PM) *

i need to know how to send output to printer using c language
need codes for hardcopy output using c language
i need help?


Did you search the forums on here for examples? Here is a link I found on DIC.

the code might look something like this:
FILE* fp = fopen("LPT1:","w");
fprintf(fp,"\nHello World\n");
fclose(fp);

Try going along those lines and see what you come up with. BTW I got this in like 5 minutes of googling.

This post has been edited by badjava: 8 Jan, 2009 - 12:14 AM
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Need Codes For Hardcopy Output Using C Language
8 Jan, 2009 - 12:17 AM
Post #4

Unix Ronin
Group Icon

Joined: 10 May, 2007
Posts: 10,438



Thanked: 198 times
Dream Kudos: 2725
Expert In: Goofing Off

My Contributions
I did that same exact thing in my store code snippet, except I ran it on Linux.

I think the biggest problem was you need to issue both \n & \r for carriage return on the printer. Otherwise the text output on the printer is all off alignment.
User is offlineProfile CardPM
+Quote Post

badjava
RE: Need Codes For Hardcopy Output Using C Language
8 Jan, 2009 - 12:28 AM
Post #5

D.I.C Regular
Group Icon

Joined: 29 Oct, 2008
Posts: 482



Thanked: 7 times
Dream Kudos: 25
My Contributions
QUOTE(no2pencil @ 8 Jan, 2009 - 12:17 AM) *

I did that same exact thing in my store code snippet, except I ran it on Linux.

I think the biggest problem was you need to issue both \n & \r for carriage return on the printer. Otherwise the text output on the printer is all off alignment.


I like that snippet. In my C++ class we didn't come across that FILE function, is that C only? It looks like it cleaned up the process of opening the printer as a file nicely if I understand what I see going on there.

The code I found has a LPT1: W and your code has lpt1 followed by a wb+, what are those for?
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Need Codes For Hardcopy Output Using C Language
8 Jan, 2009 - 12:33 AM
Post #6

Unix Ronin
Group Icon

Joined: 10 May, 2007
Posts: 10,438



Thanked: 198 times
Dream Kudos: 2725
Expert In: Goofing Off

My Contributions
Taken from http://www.cplusplus.com/reference/clibrar...tdio/fopen.html

Parameters

filename
C string containing the name of the file to be opened. This paramenter must follow the file name specifications of the running environment and can include a path if the system supports it.
mode
C string containing a file access modes. It can be:
"r" Open a file for reading. The file must exist.
"w" Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
"a" Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist.
"r+" Open a file for update both reading and writing. The file must exist.
"w+" Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
"a+" Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist.

With the mode specifiers above the file is open as a text file. In order to open a file as a binary file, a "b" character has to be included in the mode string. This additional "b" character can either be appended at the end of the string (thus making the following compound modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+").

QUOTE(badjava @ 8 Jan, 2009 - 02:28 AM) *

In my C++ class we didn't come across that FILE function, is that C only?

While it isn't C only, C++ just provides a lot more convenient methods for opening file pointers.
User is offlineProfile CardPM
+Quote Post

badjava
RE: Need Codes For Hardcopy Output Using C Language
8 Jan, 2009 - 12:47 AM
Post #7

D.I.C Regular
Group Icon

Joined: 29 Oct, 2008
Posts: 482



Thanked: 7 times
Dream Kudos: 25
My Contributions
QUOTE(no2pencil @ 8 Jan, 2009 - 12:33 AM) *

While it isn't C only, C++ just provides a lot more convenient methods for opening file pointers.


Indeed, and ty for the info smile.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 7/4/09 06:08PM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month