Jump to ID:
QNX Operating System

Project Home

Documents

Discussions

Wiki

Project Info
Forum Topic - sprintf stops working after the German umlauts ä and ö, whereas ü does work: Page 1 of 7 (7 Items)
   
 
 
sprintf stops working after the German umlauts ä and ö, whereas ü does work  
Some of the German umlauts are breaking the snprintf (and sprintf) processing.

Here is the affected code:

#include <cstring>
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    char strTmp[75];
    cout << "cout directly - " << "Umlauts: üäöÄÖÜ" << " - strlen: " << strlen("Umlauts: üäöÄÖÜ") << endl;
    strncpy(strTmp,  "Umlauts: üäöÄÖÜ", sizeof(strTmp)); // works
    cout << "strncpy       - " << strTmp << " - strlen: " << strlen(strTmp) << endl;  
    snprintf(strTmp, sizeof(strTmp), "Umlauts: üäöÄÖÜ"); 
    cout << "snprintf      - " << strTmp << " - strlen: " << strlen(strTmp) << endl; // shows only the first of the 
umlauts (ue)
    sprintf(strTmp, "Umlauts: üäöÄÖÜ");
    cout << "sprintf       - " << strTmp << " - strlen: " << strlen(strTmp) << endl; // shows only the first of the 
umlauts (ue)
}        


Each line should show all of the six German umlauts, but this is the result:

$ ./test
cout directly - Umlauts: üäöÄÖÜ - strlen: 15
strncpy       - Umlauts: üäöÄÖÜ - strlen: 15
snprintf      - Umlauts: ü - strlen: 10
sprintf       - Umlauts: ü - strlen: 10


The Momentics workspace is using the Windows cp1252 code page. Momentics is 6.3.0 SP3 on Windows XP SP2. gcc 3.3.5 is 
used:

C:/programme/QNX630/host/win32/x86/usr/bin/qcc -V3.3.5,gcc_ntox86 -c -Wc,-Wall -Wc,-Wno-parentheses  -O -Y_cpp -fmessage
-length=0 -lang-c++         main.cpp

C:/programme/QNX630/host/win32/x86/usr/bin/qcc -V3.3.5,gcc_ntox86  -lang-c++ -lang-c++ -Y_cpp    -otest    main.o  -L. -
LC:/programme/QNX630/target/qnx6/x86/lib/gcc/3.3.5 -LC:/programme/QNX630/target/qnx6/x86/lib -LC:/programme/QNX630/
target/qnx6/x86/usr/lib

Why is the string truncated after the German ü (ue)?

TiA
Christian