Thread: formatted printing with fprintf

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    formatted printing with fprintf

    How would I get my printer output with fprintf appear on separate lines under another instead of like this?

    Code:
    something
                    something
                                   and something
    I have my code as
    Code:
    fprintf(stdprn,"something\nsomething\nand something");
    Or is fprintf like cprintf() where it doesn't translate the new line escape sequence? So I would have to put a return carriage before it?

    I'm using Borland C++ 4.5 under Windows 95.
    thank you again.
    Last edited by lambs4; 11-19-2001 at 07:54 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The problem isn't so much as a problem with fprintf, but rather, how the text editor you're viewing it with interprets it. When it originated, the \n line was just a new line. Which would do what you want. The \r was used to return the cursor to the beginning of whatever line you were on. This is why the combination "\n\r" is used.

    You'll likely have to pad the line with spaces. Not as simple as just using \n.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    No, when I print directly to the printer by the program. When "something" prints it comes out as I've said in the original message. Although I tried putting \n\r and It did print as I wanted it to like the following.

    Code:
    something
    something
    and something
    Thanks for you help.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Ok, you want it to come out how?
    Code:
    abc
       def
          hij
    So that, there are 3 spaces before 'd', and 6 before 'h', so they're all directly one line below eachother? Well then, \n should work:

    abc\ndef\nhij

    Yes, fprintf does translate them right. It's your printer or file viewer that isn't interpreting them correctly. fprintf just takes what you give it, and passes it off as it receives it.

    If fprintf wasn't escaping the n character, you would get your whole string "abc\ndef\nhij" printed out all on the same line. It is passing it correctly, it's just your printer isn't working with the \n right.

    As I said, \r returns to the beginning of the line. \n keeps the current position, but drops 1 line down. It's possible you're having problems with the printer's head advancing foreward incorrectly.

    This is not a fprintf problem.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I want the come to be like this:

    abc
    def
    hij

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    try
    Code:
    fprintf(stdprn,"something\n\rsomething\n\rand something\n\r");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fprintf in void function Not Printing
    By thetinman in forum C Programming
    Replies: 5
    Last Post: 10-17-2006, 05:13 PM
  2. help with basic program
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 02-01-2006, 04:19 PM
  3. program not working...please look at this
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 01-30-2006, 10:33 PM
  4. printing error using fprintf
    By ahming in forum C Programming
    Replies: 7
    Last Post: 05-26-2005, 09:45 PM
  5. Help with formatted printing with arrays
    By nizbit in forum C Programming
    Replies: 2
    Last Post: 12-11-2004, 01:52 PM