Hello!
Peter van der Veen wrote:
Add
setlocale(LC_CTYPE,“C-TRADITIONAL”);The default multibyte encoding is utf-8 (default for C99). When an invalid
utf-8 encoding is found the current printf multibyte parser does not sync up
after the invalid utf-8 characters. Adding this setlocale() call changes the
multibyte encoding to a direct mapping. Before C99 the default multibyte
encoding was not defined and implementations seemed to ignore it passing
everything through as-is. As the other OS’s start to implement C99, they may
stop working as well. If we make the syncing up after an invalid utf-8
character work better, your example may start working. I will see what we
can do for the future.
Great! Everything works fine now! The great thing about QNX is the
direct support we get from you guys…
It would have been nice if the compiler had complained about it since
the solution is so simple.
===
#include <stdio.h>
#include <locale.h>
int main(void)
{
setlocale(LC_CTYPE,“C-TRADITIONAL”);
printf(“char %c code %d char again: %c number: %d\n”, ‘é’, ‘é’, -23,
1);
printf(“pre: %d petit numéro problématique: %d\n”, 1, 1);
printf(“petit num%cro: %d\n”, ‘é’, 1);
printf(“petit num\x0e9ro: %d\n”, 1);
}
$ qcc output.C -o output
$ ./output
char é code -23 char again: é number: 1
pre: 1 petit numéro problématique: 1
petit numéro: 1
petit numéro: 1
Thanks again,
–
Ricky Ng-Adam, stagiaire laboratoire de robotique
(450) 652-8499 x 2757, local BR0.50
Hydro-Québec, Montréal, Canada