-
June 5th, 2009, 01:45 AM
#1
Working with accented characters in C++ (Linux)
Hi,
I am working with strings in a program that I am developing in C++ using Geany (Linux/Ubuntu). The main issue is that I have to work with texts written in Spanish, so they contain characters such as "á", "é" or "ñ".
One of the functions that I need most is to find the ASII code of each character in a string. I have found a way to do this:
//
char caracteres[128];
string segmento;
int asciicode;
segmento="á, é, ó are characters that can be found in this sentence";
strcpy(caracteres, segmento.c_str());
asciicode=int(caracteres[1]);
//
This is, I convert the string to a char variable and then I get the ASCII codes. The problem is that this does not seem to work correctly with accented characters. For instance, the character "Ã*" seems to be split in two "chars" with two ASCII codes, -61 and -83, when it should be just one code: 237. I think that this is because I get the strings reading UTF-8 files, but this is something that I can not change.
Could someone please help me find a way to get the right ASCII code for the characters of a string, even the accented letters?
Many thanks!!!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|