L
lothar.behrens
Hi,
I had or even have a problem with functions, that are returning char
arrays.
I want to translate text that should be internationalized. So the
following
function definition, I thought, would be good:
char* translateText(char* text);
This function could be used very simply at any place. But what is, if
the
translated text is bigger than the orginal string and the string is a
constant ?
Then I have defined a global char* pointer to be used. Every time I
translate
a text, I realloc needed memory and then translate.
The reallocation is done in an extern locale implementation, so not
shown
here.
Now the problem: I cannot use more than one call to translateText for a
function parameter. There would be an overwrite of the first use by the
second use of that function, before the real function gets the
translated
text.
How to solve this ?
Are there usual solutions ?
Thanks
Lothar
This is the current code:
char* translated = NULL;
char* translateText(char* text) {
Locale locale;
locale->translate(&translated, text);
return translated;
}
char a[] = "Car";
char b[] = "Tree";
printf("%s is %s and %s is %s\n", a, translateText(a), b,
translateText(b));
I had or even have a problem with functions, that are returning char
arrays.
I want to translate text that should be internationalized. So the
following
function definition, I thought, would be good:
char* translateText(char* text);
This function could be used very simply at any place. But what is, if
the
translated text is bigger than the orginal string and the string is a
constant ?
Then I have defined a global char* pointer to be used. Every time I
translate
a text, I realloc needed memory and then translate.
The reallocation is done in an extern locale implementation, so not
shown
here.
Now the problem: I cannot use more than one call to translateText for a
function parameter. There would be an overwrite of the first use by the
second use of that function, before the real function gets the
translated
text.
How to solve this ?
Are there usual solutions ?
Thanks
Lothar
This is the current code:
char* translated = NULL;
char* translateText(char* text) {
Locale locale;
locale->translate(&translated, text);
return translated;
}
char a[] = "Car";
char b[] = "Tree";
printf("%s is %s and %s is %s\n", a, translateText(a), b,
translateText(b));