ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
In practical terms, you give it the the beginning and end of a sequence to operate on, an original value to replace, and a new value to replace it with. In your code, the third parameter is a negative number, not a character. Not sure exactly what you were thinking that param was for. Anyway, since the algorithm is actually a template, the compiler is saying that it couldn't find any way to instantiate the template such that it would be an acceptable match for the way you tried to call the function.
In practical terms, you give it the the beginning and end of a sequence to operate on, an original value to replace, and a new value to replace it with. In your code, the third parameter is a negative number, not a character. Not sure exactly what you were thinking that param was for. Anyway, since the algorithm is actually a template, the compiler is saying that it couldn't find any way to instantiate the template such that it would be an acceptable match for the way you tried to call the function.
its a ascii code and it's acceptable because there isn't a difference between 'a' and 25
Gotta agree with lowpro2k3 here. For example, the parameter, -121, that you give in the first line doesn't correspond to and ASCII character I know. I believe ASCII is a 7-bit unsigned encoding, so only values 0-127 make sense.
The chstrswithf() example will work with a null-terminated C-string, but it is not a good idea to try it with a C++ STL string. The implementation is not guarunteed to store the string as a null-terminated buffer. For example, it is possible that it could be implemented to store a buffer and a size.
string convert(string str_in)
{
for(int i = 0; i < str_in.length(); i++)
{
switch(str_in[i])
{
case 's':
str_in[i] = 'f';
break;
}
}
return str_in;
}
Is there a better way?
Also you're using the function argument as a return value - no need, you can pass by reference instead in that situation.
Code:
void convert(string & str_in)
{
// it seems from your switch case you want to swap 's' with 'f'
replace(str_in.begin(), str_in.end(), 's', 'f');
...
}
I've never really used the replace() function, but depending on the return codes of it, you might want to check that in your function and return an int instead of void.
well, I'm sorry but some of the characters that I want to replace aren't in the ascii table nor in the extended ascii table
I don't know if you are able to see these characters but here is the list.
I can't find them in the table, and I'm pretty sure they are negative numbers because I tested the converter that I've used with normal characters, and they were just fine
'ð' ('g' with a line on it)
'þ' ('s' with a hook)
'ý' ('i' without the dot on it)
I've found them in the ascii table
'ç' ('c' with a hook)
'ö' ('o' with double dots on it)
'ü' ('u' with double dots on it)
These are Turkish characters,
any idea??
thanks for help
PS:
Code:
string convertTR(string str_in)
{
for(int i = 0; i < str_in.length(); i++)
{
switch(str_in[i])
{
case -121:
str_in[i] = 'c';
break;
case -89:
str_in[i] = 'g';
break;
case -115:
str_in[i] = 'i';
break;
case -108:
str_in[i] = 'o';
break;
case -97:
str_in[i] = 's';
break;
case -127:
str_in[i] = 'u';
break;
}
}
return str_in;
}
If you're not convinced that negative numbers work, try this pls and see yourself
I can't find them in the table, and I'm pretty sure they are negative numbers because I tested the converter that I've used with normal characters, and they were just fine
'ð' ('g' with a line on it)
'þ' ('s' with a hook)
'ý' ('i' without the dot on it)
I've found them in the ascii table
'ç' ('c' with a hook)
'ö' ('o' with double dots on it)
'ü' ('u' with double dots on it)
These are Turkish characters,
any idea??
Can't you just assign the value to a char and use it as a replacement value?
I understand that you might not be able to enter the values in the compiler, but since you are reading them from file in
the first place, you could set up a resource file where you could store these characters and read them in at the beginning of
the program.
I haven't tested this out because I don't have Turkish fonts, but it seems to me like it should work.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.