Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Working with ASCII values in C++?

I'm trying to put interleaved 2 of 5 barcodes on a .pdf report that I'm generating, but am running into trouble. The barcode font expects me to give it ASCII values rather than CString values. Specifically, the ASCII value has to be the CString value plus 33: i.e. to represent the number 1, I have to give the font the ASCII value 34, to represent the number 10, I have to give the font the ASCII value 43, and so on.

I'm so confused. I have to take a CString, turn it into an ASCII value, add 33 to that ASCII value, and then print this new ASCII value in a particular barcode font. On top of that, the virtual print engine I'm using to generate the .pdf report (Ideal Software) expects the value that I print to be a LPCSTR.

Can anyone give me any tips on working with ASCII characters and converting them to and from the various formats that I need?

3 Answers

Relevance
  • ?
    Lv 7
    1 decade ago
    Favorite Answer

    CStrings nominally store ASCII values. "A", "1" are ASCII values.

    In this case, you're not really storing ASCII's in the CString, but the N+33 values the barcode wants. Just focus on putting those values into the right places in the CString. (Hint: since you have only a handful of possible values, a simple subscript into a character array will be very fast.) Make sure the CString has a zero-byte terminator to be safe.

    And I think referencing the CString in a function call will automatically convert it to LPCTSTR.

    Hope that helps.

    Source(s): The Visual C++ Help Index: CString objects/C++ string manipulation
  • Anonymous
    1 decade ago

    If you cast "1" to int you'll have a value of 49 (not 33) - the digits 0-9 have values from 48-57. So you'll have to use the cast value - 16, then cast it back to a string to print it. (Or get a more sand algorithm - like print the actual character using a 2 of 5 font. Then you just have to create the lead-in and lead-our characters [if 2 of 5 works that way - it's a barcode I'm not familiar with] and the checksum.).

  • 4 years ago

    this form of characters are non-printable. despite the fact that, all of them would be having some specific keysequences which incorporate: 'b' Backspace 'n' new line 'a' beep sound 't' tab 'r' line injury Do refer ASCII tables that are given on the tip of the books for added information of left arrow, proper arrow and so on

Still have questions? Get your answers by asking now.