A
Ahmad
Hi all,
I have written a simple c++ app, as I'm still learning c++. The
thing works flawlessly on VC++6, but just doesn't work on g++. The
transliterate function which causes the problem is supposed to search
for some characters (2 or 1) and replace them with their equivalent
Arabic characters from an array vector<string>. I have been debugging
it on Linux for like 6 hours, and it's really boring that it works on
vc++.
Anyway, tons of thank yous to anyone that can help me with this one:
PS: I noticed:
arabic.size() returns 0??
if I replace it with a number like 6, it just crashes?!
declarations
------------
std::vector<std::string> arabic; //Array for arabic letters
std::vector<std::string> english; //Array for english letters
std::vector<std::string> comments; //Array for comments (ignored)
code
--------
std::string arabize::transliterate(std::string user_ip){
std::cout << "In arabize Transliterator" << std::endl;
std::string CharOrTwo;
std::string text_out; //Holds the Arabic processed text
bool MatchFound=false;
if (user_ip.length() < 1) { std::cout << "Write some text first!" <<
std::endl; return "";}
for(int i=0; i < user_ip.length() ; ++i){
//Loops over all input characters
if (i < (user_ip.length()-1)){ //If not at last char
CharOrTwo = user_ip.at(i);
CharOrTwo += user_ip.at(i+1); //Take next 2 chars
for(int ctr = 0; ctr < arabic.size(); ctr++) //Problems here
if (CharOrTwo == english[ctr] ){ //Are they in our dictionary?
MatchFound=true;
text_out += arabic[ctr]; //Put their Arabic equivalent
}
if (MatchFound) {MatchFound=false; i++;continue;}//i++ bec we
worked on 2 chars
}
//Next 2 chars didn't match, or we're at last char.
//So, let's match this char we are at
CharOrTwo = user_ip.at(i);
for(int ctr = 0; ctr < arabic.size(); ctr++) //Again is it in
dictionary
if (CharOrTwo == english[ctr] ){
MatchFound=true;
text_out += arabic[ctr]; //Put their Arabic equivalent
}
if (MatchFound) {MatchFound=false;continue;}
}//Done iterating over all input chars
#ifdef _DEBUG
std::cout << "Input:" << user_ip << std::endl <<
"Output:" << text_out << std::endl;
#endif
return text_out;
}
I have written a simple c++ app, as I'm still learning c++. The
thing works flawlessly on VC++6, but just doesn't work on g++. The
transliterate function which causes the problem is supposed to search
for some characters (2 or 1) and replace them with their equivalent
Arabic characters from an array vector<string>. I have been debugging
it on Linux for like 6 hours, and it's really boring that it works on
vc++.
Anyway, tons of thank yous to anyone that can help me with this one:
PS: I noticed:
arabic.size() returns 0??
if I replace it with a number like 6, it just crashes?!
declarations
------------
std::vector<std::string> arabic; //Array for arabic letters
std::vector<std::string> english; //Array for english letters
std::vector<std::string> comments; //Array for comments (ignored)
code
--------
std::string arabize::transliterate(std::string user_ip){
std::cout << "In arabize Transliterator" << std::endl;
std::string CharOrTwo;
std::string text_out; //Holds the Arabic processed text
bool MatchFound=false;
if (user_ip.length() < 1) { std::cout << "Write some text first!" <<
std::endl; return "";}
for(int i=0; i < user_ip.length() ; ++i){
//Loops over all input characters
if (i < (user_ip.length()-1)){ //If not at last char
CharOrTwo = user_ip.at(i);
CharOrTwo += user_ip.at(i+1); //Take next 2 chars
for(int ctr = 0; ctr < arabic.size(); ctr++) //Problems here
if (CharOrTwo == english[ctr] ){ //Are they in our dictionary?
MatchFound=true;
text_out += arabic[ctr]; //Put their Arabic equivalent
}
if (MatchFound) {MatchFound=false; i++;continue;}//i++ bec we
worked on 2 chars
}
//Next 2 chars didn't match, or we're at last char.
//So, let's match this char we are at
CharOrTwo = user_ip.at(i);
for(int ctr = 0; ctr < arabic.size(); ctr++) //Again is it in
dictionary
if (CharOrTwo == english[ctr] ){
MatchFound=true;
text_out += arabic[ctr]; //Put their Arabic equivalent
}
if (MatchFound) {MatchFound=false;continue;}
}//Done iterating over all input chars
#ifdef _DEBUG
std::cout << "Input:" << user_ip << std::endl <<
"Output:" << text_out << std::endl;
#endif
return text_out;
}