exit is defined in <stdlib.h>, so make sure you #include that header file.
matsp meant that after that code has executed, the FILE stream flpt has been opened, and you can write to it. For example:Also, what do you mean when you say "Then use "flpt" as your destination file"?
And, of course, everything printed to this file stream gets send to the printer. Theoretically.Code:fprintf(flpt, "This goes to the printer.\n");
You could also try the non-standard stdprn, although I hear it doesn't exist under MSVC. http://www.thescripts.com/forum/thread218908.html
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Sorry to bring up old news guys, but I finally got a hold of a computer with a printer. I coded this, and nothing happened:
Missing anything?Code:#include <stdio.h> #include <stdlib.h> int main() { FILE *flpt; flpt = fopen("lpt:", "w"); if (flpt == NULL) { perror("open LPT:"); exit(1); } fprintf(flpt, "Test print.\n\nTest print.\n\nTest print.\n\n"); }
Actually, you may need to use "LPT1:" (or some other number after LPT and before .
Also, some printers need special instructions to tell it to print things (e.g. a postscript printer will most likely not do anything meaningfull if you just send some text to it).
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Okay, so
fixes that problem, right? Now, what would I do to tell the printer to print?Code:flpt = fopen("lpt1:", "w");
How is the printer connected to your machine?
What printer is it?
It's highly likely that a USB printer will not respond to "LPT1:", for example.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
It has to be functional on any printer. I test it with a USB printer, so what number do you suggest if not 1, or do I not even use a number?
Thanks
-Matt
If you want it to work on any printer, don't do it yourself. Use the operating system. It will have drivers for every printer that works with the system. An easy way to do this would be to output to a file, and have the user print this file. I'm sure this could be arranged with a system() call if you wanted to do it automatically.
Plus, I would find a program that printed something every time it was executed rather annoying.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
I need it to print by itself every time. If that isn't possible to do on more than one printer, I guess I could find out what kind.
Your best bet in that case is to use a command line utility, in my opinion. Perhaps one of these will help.
http://www.google.ca/search?hl=en&q=...e+Search&meta=
http://www.robvanderwoude.com/2kprintcontrol.html
I found out that XP has a "print" command. http://www.ss64.com/nt/print.html
It looks like it just uses LPT1, though.
It might help to know what printer you have.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
So I have to scrap my whole thing?
Not necessarily. You could create a file at first, and then if you figure out how to print directly, implement that instead . . . .
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Ok, so, I am a complete beginner, to accessing other files. I barely understand how what I have works. I hate to do it, but I need to ask for help on that one.
So what DO YOU have at the moment?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I have:
And I know that system() might help, but I have no idea what that does.Code:#include <stdio.h> #include <stdlib.h> int main() { FILE *flpt; flpt = fopen("lpt:1", "w"); if (flpt == NULL) { perror("open LPT:"); exit(1); } fprintf(flpt, "Test print.\n\nTest print.\n\nTest print.\n\n"); }