I am trying to get proper character descriptions out of a legacy FAME database file. Basically this works, but the umlauts etc. are not printed correctly. Basically the following C function that is contained in the R Package FAME
to this is rather a C question than an R question.
void fameWhat(int *status, int *dbkey, char **objnam, int *class,
int *type, int *freq, int *basis, int *observ,
int *fyear, int *fprd, int *lyear, int *lprd,
int *obs, int *range,
int * getdoc, char **desPtr, char **docPtr){
/* Get info about an object. Note that range should be an int[3] on input */
int cyear, cmonth, cday, myear, mmonth, mday;
int i;
char fdes[256], fdoc[256];
if(*getdoc){
if(strlen(*desPtr) < 256 || strlen(*docPtr) < 256){
*status = HBNCHR;
return;
}
for(i = 0; i < 255; ++i) fdes[i] = fdoc[i] = ' ';
}
fdes[255] = fdoc[255] = '\0';
cfmwhat(status, *dbkey, *objnam, class, type, freq, basis, observ,
fyear, fprd, lyear, lprd, &cyear, &cmonth, &cday, &myear,
&mmonth, &mday, fdes, fdoc);
if(*getdoc){
strncpy(*desPtr, fdes, 256);
strncpy(*docPtr, fdoc, 256);
}
if(*status == 0 && *class == HSERIE)
cfmsrng(status, *freq, fyear, fprd, lyear, lprd, range, obs);
return;
}
I feel that due to the fact that the pointer to pointer desPtr
which points to the description is of type char
I do not get any proper umlauts when calling this function from R and displaying the result within an R console. I have a hunch that FAME is Latin-1 encoded. R is UTF-8. For ä
I get \U3e34653c
for example.
So is there a way of getting it done already in C and pass proper values to R or should I rather search and replace within R?
Note: I have seen this thread Using Unicode in C++ source code and this How to use utf8 character arrays in c++? .