cancel
Showing results for 
Search instead for 
Did you mean: 

sprintf function and Cyrillic

Alex Golubev
Associate II

I ran into the following problem the sprintf(str, "привет") function; encodes in a two-byte format. Each even character = 208 (dec).

str[0]	char	208 '�?'	
str[1]	char	159 '\237'	
str[2]	char	209 'Ñ'	
str[3]	char	128 '\200'	
str[4]	char	208 '�?'	
str[5]	char	184 '¸'	
str[6]	char	208 '�?'	
str[7]	char	178 '²'	
str[8]	char	208 '�?'	
str[9]	char	181 'µ'	
str[10]	char	209 'Ñ'	
str[11]	char	130 '\202'

11 REPLIES 11
Pavel A.
Evangelist III

Maybe both source and target charsets for gcc should be specified:

gcc -finput-charset=CP866 -fexec-charset=CP866

Depends on the default with which gcc was built.

I tried also to pretend that both charsets are UTF-8 (though source is CP866) ; it seems to work.

 gcc -finput-charset=utf-8 -fexec-charset=utf-8

0693W000007BZFzQAO.jpgOutput:

$ gcc -finput-charset=UTF-8 -fexec-charset=utf-8 ***.c

$ ./a.out

[0] AF

[1] E0

[2] A8

[3] A2

[4] A5

[5] E2

[6] 00

strlen=6

 As you see the string is correctly encoded in 866, each char one byte.

-- pa

Alex Golubev
Associate II

How to add cp866 to the debugger?