473,413 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Print a text file

114 100+
Is it possible to print a text file using C?
like, to get filename as input and then to print it?
Sep 28 '07 #1
8 3403
sicarie
4,677 Expert Mod 4TB
Is it possible to print a text file using C?
like, to get filename as input and then to print it?
Yes. Have you looked at file IO? It's very similar to C++, you declare the filehandle, open it up, get the contents and do whatever you like with them.

Have a look at this.

The thing you may want to watch out for is the path to the file - there's all sorts of fun to be had backwhacking the path if it's not in the same directory as the program you're executing.
Sep 28 '07 #2
Firecore
114 100+
Yes. Have you looked at file IO? I.
I am aware of file io and that site. it is where i learnt file io.
but how do we print stuff?
Sep 29 '07 #3
RRick
463 Expert 256MB
Use printf to print to the console window. Do you remember the "Hello World" program? http://en.wikipedia.org/wiki/Hello_world_program

Another way is to use fprintf to print to a file. A description of fprintf is in the above post.
Sep 29 '07 #4
Firecore
114 100+
Use printf to print to the console window. Do you remember the "Hello World" program? http://en.wikipedia.org/wiki/Hello_world_program

Another way is to use fprintf to print to a file. A description of fprintf is in the above post.
i dont think u guys get what i mean by "print". How do we print through the printer?
Sep 29 '07 #5
RRick
463 Expert 256MB
Do you mean getting a printout from the printer or getting the printer to work directly with your program?
Sep 30 '07 #6
Firecore
114 100+
Do you mean getting a printout from the printer or getting the printer to work directly with your program?
getting a printout from the printer
Sep 30 '07 #7
hsn
237 100+
getting a printout from the printer


that is a very intresting question
I'm waiting for the answer too.
Sep 30 '07 #8
If you are coding C for UNIX, you open the device file /dev/lp0 and write to it as if it were a regular file, the text will go out on the printer; using fopen("/dev/lp0","w") and then fprintf(...).

I think that when coding C for MSDOS, there is a device file named PRN, Im not sure. It usally doesnt work because modern printers have a set of printing languages that you would need to master before sending anything directly to the printer.

If you are coding C in a Windows machine, thats a longer road to go through. You need to do some Win32 programming and make use of the GDI. The GDI is a subsystem that lies between the printer drivers and your code.

This works this way, you may start by calling PrintDlg() to let the user pick a printer. This function fills an structure that gives you information you need when calling CreateDC().

First call CreateDC(), this function gives you a handle that you must store.
Then to actually start printing, call StartDoc(). Then use the GDI functions to draw your text or whatever you want to the handle you saved previously ( like TextOut() to write text ). You may call StartPage() and EndPage() to print several pages. Finally Call EndDoc() and DeleteDC() when you are done printing.
Sep 30 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: MouseHart | last post by:
I've written a simple program in VB 6.0 to list all my MP3 files. To show them on the screen I used an MSFlexGrid named TextGrid (which is not associated with any table or text file) in the...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
7
by: Ron | last post by:
Hi All, Is it possible to have Access print a report, identical to one that would print to a printer, only print to a "standard" text file? I can't find it in help and when I try to just print...
3
by: itdaddy | last post by:
hey perl gurus! i am new to this forum cause i need help. I have done many scripts. but i want to use perl to do this: What I want to do is this. I have a QRP file that I can convert to a txt...
2
by: alivip | last post by:
when I wont to inser (anyting I print) to the textbox it will not inser it just print then hanging # a look at the Tkinter Text widget # use ctrl+c to copy, ctrl+x to cut selected text, #...
12
by: Studiotyphoon | last post by:
Hi, I have report which I need to print 3 times, but would like to have the following headings Customer Copy - Print 1 Accounts Copy - Print 2 File Copy -Print 3 I created a macro to...
16
by: raylopez99 | last post by:
I am running out of printing paper trying to debug this...it has to be trivial, but I cannot figure it out--can you? Why am I not printing text, but just the initial string "howdy"? On the...
2
by: dmorand | last post by:
When I try to print a 'print version' of my page it looks fine in IE 7, but when I print in IE 6 the margins are all screwed up. The page itself looks the same in both browsers, it's just when I...
66
by: happyse27 | last post by:
Hi All, my html code is sno 1) and perl code is sno 2). a) I tried to print $filename and it cant print out the value, only blank was displayed, and the file could not be uploaded. And it...
11
by: JWest46088 | last post by:
I'm having difficulty trying to figure out how to print a text file from a hash table one line at a time. I have the text file read into the hash table and can print the text file all at once, but I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.