Thread: receivung a NULL pointer

  1. #1
    Unregistered
    Guest

    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.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    28
    Try replacing PRN with LPT1

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    66
    tried that and stdprn but it makes no diffrence.
    T

  4. #4
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Try:
    lpt2

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    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.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    66
    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
    T

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Well, 1) what OS are you running?
    2) Is the printer a local printer on a parallel port, or a network printer?

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    66
    1) Win32
    2) local
    T

  9. #9
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    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.

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    66
    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
    T

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    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");

  12. #12
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    I tried to edit that last message, but no luck:

    Make that:
    UINT return_val;
    return_val = WinExec("print \\subdir\\filename.txt",SW_SHOW);

    Include <windows.h> header.

  13. #13
    Registered User
    Join Date
    Oct 2001
    Posts
    66
    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.
    T

  14. #14
    Registered User
    Join Date
    Oct 2001
    Posts
    28
    I don't want to ask the obvious but you have switched your printer on haven't you
    lol!!!
    Last edited by SPOOK; 10-13-2001 at 02:25 PM.

  15. #15
    Registered User
    Join Date
    Oct 2001
    Posts
    66
    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
    T

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. addrinfo Structure Not Working
    By pobri19 in forum Networking/Device Communication
    Replies: 9
    Last Post: 10-22-2008, 10:07 AM
  2. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  3. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 11:27 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM