Sprintf () handling% s extended ASCII (ISO 8859-1) in some modes of operation?

I use ISO 8859-1 (latin extended ASCII char) in my C application. When I strcpy/ strcatparts of a string together, it works fine. But when I use sprintf("%s %s"), in some versions (especially in some versions of Android) the string will be truncated when the extended ASCII character is deleted (in particular é, although I have not tried others yet).

I thought that %sI just had to copy the bytes until it was '\0'. I suspect that strcpy/ strcatworks because it does just that, without any formatting. What could be happening here?

I should note that I am not viewing text using printf(), rather than my own text rendering engine, which does an excellent job with ISO-8859-1.

UPDATE: To clarify, I have an NDK application that stores a string in C and passes it to my OpenGL-based rendering engine. If I pass the complete string as a char * literal, it will display in order. If I sprintf () the parts together, it truncates the é character. For example:

char buffer[1024];
strcpy(buffer, "This is ");
strcat(buffer, "the string I want to diésplay.");

It's good. But this:

sprintf(buffer, "%s%s", "This is ", "the string I want to diésplay.");

Prints as:

This is the string I want to di
+4
source share
1 answer

s[n]printf() , , strcpy() strcat(). printf - . , . , C , printf() (, ), sprintf().

"f" "printf" "". , , , , , . , ( " , " ), , , .

, , . , , , , . , , , , , , . , getlocale() setlocale(), , , .

printf , , , , : C- , strcpy() strncat(), . stdio , .

+1

Source: https://habr.com/ru/post/1626382/


All Articles