Thread: printer outputting odd chars?

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    27

    printer outputting odd chars?

    My program is *almost* done, however whenever I send certain chars to print, eg. the british pound sign "£" gets printed as a "ú". Similarly ‘ and ’ get printed as æ and Æ.

    I'm guessing it is to do with the program using unicode and the printer wanting ascii.

    How do I fix this?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    If you are using standard library functions (printf etc...) then read this thread: http://cboard.cprogramming.com/c-pro...E-console.html

    One possible option is to use unformatted, binary I/O when sending bytes to you printer - so at least you know exactly what your printer is receiving.

    gg

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    27
    It's actually an input where I want to be able to put say "apple £1.50" and have it print it. I'm then printing the string to LPT1.
    I can of course just hardcode it to print the char "\xa3" but I was wondering if there was anyway to address the discrepancy between the program and the printer so it can be typed?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Once you step outside the 7-bit ASCII character set, things have a tendency to get a little bit fuzzy from time to time.

    Unless everything in the sequence of printing something is full UNICODE, then you need to consider a few things.
    - the character set(s) supported by the compiler run-time (or locale)
    - the character set(s) of the OS
    - the character set(s) of the printer.
    - Are you creating a console or GUI program (GUI tends to make it easier)
    - Are you raw characters to the printer (like an ancient line printer), or is it more abstract (like say postscript)?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    27
    I've created a wxwidgets gui program which takes a wxtextctrl input and converts it to a string to be processed. I believe everything supports unicode except the printer.

    The computer is a standard english Windows XP 32-bit machine.
    The printer is an EPSON LX-300 dot matrix printer and takes ascii input with EPSON ESC codes.

    What is puzzling me is that the hex for the £ symbol is the same in ascii and unicode: a3 so I'm not entirely sure why the printer is putting out a ú which is hex fa

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    See page 14 ("Printing a Hex Dump") of http://ftp.epson.com/pdf/lx300p/lx300ppg.pdf
    It will help you figure out what is really going to the printer.

    It's probably also worth checking whether you're sending the font to the printer, or using the built-in fonts of the printer.

    Also, check you're using the best windows driver for this printer (and not some fallback generic Epson printer).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    http://www.tachyonsoft.com/uc0000.htm#U00A3
    http://www.tachyonsoft.com/uc0000.htm#U00FA

    £ = 0x9C or 0xA3, depending on codepage
    ú = 0xA3 or 0xFA, depending on codepage

    0xA3 is "ú" under the CP437 (DOS), and "£" under CP1252 (Windows Latin-1). For Windows console I/O, you'll may need to get all "layers" to agree on the same codepage:
    Code:
        setlocale(LC_ALL, "");
        SetConsoleOutputCP(GetACP());
        SetConsoleCP(GetACP());
    This code is explained in the thread I linked to in post #2. You may also need to change the font used by cmd.exe to "Lucida Console" instead of "Raster Fonts".

    gg

  8. #8
    Registered User
    Join Date
    Nov 2009
    Posts
    27
    fab, ok thank you both, I'll have a go now and see where I can go with this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Set Printer Prior To Loading Print Dialog Box
    By Beaner in forum Windows Programming
    Replies: 3
    Last Post: 10-10-2008, 01:02 PM
  2. changing property (layout) of a printer
    By leojose in forum Windows Programming
    Replies: 5
    Last Post: 12-05-2005, 07:16 AM
  3. Success - Output to Printer
    By noraa in forum C Programming
    Replies: 5
    Last Post: 08-04-2002, 09:12 AM
  4. fancy strcpy
    By heat511 in forum C++ Programming
    Replies: 34
    Last Post: 05-01-2002, 04:29 PM
  5. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM