Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get ASCII value of a Character?

Status
Not open for further replies.

hstijnen

Programmer
Nov 13, 2002
172
NL
Hi,

How can I get the ASCII (integer) value of a Character in C++ (and vice versa)? In PAscal you have therefore int = ORD(char) and char = CHR(int). What are the equivalents in C++?

Background:
I want to read data from an Excel file. I'v saved it as dbf and connected with a TTable. Works OK. But some characters are ill formed. E.g. an é (e with accent) in Excel becomes an unreadable character in my TTable. To solve this problem I want to scan the string and replace the bad characters on the basis of the underlying ASCII/integer values of the chars.

Thanks for your help

Henk
 
Well, C/C++ is low-level enough that char is ALSO an integer, so you already know ASCII value. just write
int ascii_val = (int)character; or something like this

However, I'm not sure that this is the right way of solving the problem - instead, set the language driver in DBE administrator to the same language in your Excel file (and do the same thing in your app) and you shouldn't have that problem anymore
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top