-
receivung a NULL pointer
I am a beginner to programming and I am trying to get my program to to print data to my printer but I am faced with two problems depending which comiler I use.
/* program as follows */
FILE *p_ptr;
if( ( p_ptr = fopen("PRN", "w") ) == NULL )
{
/* some error message */
}
fprintf(p_ptr, "some data here");
1. (old Boland compiler): It doesn't return a NULL pointer but nothing prints. I get a time out message.
2. (New boland compiler): It returns a NULL pointer.
I also believe that it would be quicker to writd the data to a text file and then print that how do I do this.
If you can help me with any of the above I would be very greatful.
-
Try replacing PRN with LPT1
-
tried that and stdprn but it makes no diffrence.
-
-
Also, this is the DOS-style way of printing (and you should use "LPTx") -- is your printer set up to handle this? You need to make sure that LPTx is actually a valid printer port, either a true parallel port or a port that windows sets up to allow DOS programs to print over a network, and that there's a printer on it.
You can go into the printers control panel to see what LPT ports, if any, your printers are assigned, though I forget exactly where the info shows up for cases where you have networked printers. Most networked printers will NOT use LPT1, as this is usually reserved for a physical parallel port.
-
Cheers for the help but i am still no nearer to solving the problem any more ideas as I am getting a real head ache with this now
-
Well, 1) what OS are you running?
2) Is the printer a local printer on a parallel port, or a network printer?
-
-
Plus, win32 -- is this a 9x (95, 98, Me) or NT style (Nt4, 2000, XP) machine? I know the method you're trying works under the 9x series, but it could be that, as NT machines have no "true" DOS, that certain operations, which are DOS operations, won't work properly under their emulated DOS.
You may need to use a Win32 means of printing -- see the WinAPI for information on that.
-
It is a windows 98. As for wether or not the printer is compatable I have no idea but I will try to find out about that
Thanx
-
You could try writing to a file, then printing the file with either:
UINT return_val WinExec("print \\subdir\\filename.txt",SW_SHOW);
or
system("print \\subdir\\filename.txt");
-
I tried to edit that last message, but no luck::eek:
Make that:
UINT return_val;
return_val = WinExec("print \\subdir\\filename.txt",SW_SHOW);
Include <windows.h> header.
-
Thanx for all the help but I still can't get it to work.
Is there any other ways that I can print out my data for a hard copy or not?
At the moment I am just saving it to another file i.e temp.txt and then after I close the program I have to open that and select File > print. As you can appreciate this is largely inpractical.
-
I don't want to ask the obvious but you have switched your printer on haven't you
lol!!!
-
Cheers that was the problem I have fixed it now a technical problem of pressing the on button (NOT!)
no it prints fine from other programs.
I have tried the advice above and it always reports errors:
include windows.h although I have ( does this header file come with borland compiler as you know)
and that the function system isn't declared