Questions tagged [widechar]

widechar is a generic name for character sets wider than ASCII

The term widechar is a generic name for character sets wider than 8 bits. Generally this means some (unspecified) 16 or 32 bit Unicode encoding.

203 questions
45
votes
8 answers

Why does the Java char primitive take up 2 bytes of memory?

Is there any reason why Java char primitive data type is 2 bytes unlike C which is 1 byte? Thanks
realnumber
  • 2,124
  • 5
  • 25
  • 33
40
votes
2 answers

What is a "wide character string" in C language?

I came across this in the book: wscanf(L"%lf", &variable); where the first parameter is of type of wchar_t *. This s different from scanf("%lf", &variable); where the first parameter is of type char *. So what is the difference than. I have never…
quantum231
  • 2,420
  • 3
  • 31
  • 53
39
votes
4 answers

Windows API: ANSI and Wide-Character Strings -- Is it UTF8 or ASCII? UTF-16 or UCS-2 LE?

I'm not quite pro with encodings, but here's what I think I know (though it may be wrong): ASCII is a 7-bit, fixed-length encoding, with the characters you can find in ASCII charts. UTF8 is an 8-bit, variable-length encoding. All characters can be…
user541686
  • 205,094
  • 128
  • 528
  • 886
29
votes
3 answers

What's the difference between printf("%s"), printf("%ls"), wprintf("%s"), and wprintf("%ls")?

Consider this sample program: #include #include #include int main() { std::string narrowstr = "narrow"; std::wstring widestr = L"wide"; printf("1 %s \n", narrowstr.c_str()); printf("2 %ls \n",…
Display Name
  • 947
  • 2
  • 10
  • 18
21
votes
1 answer

Understanding and writing wchar_t in C

I'm currently rewriting (a part of) the printf() function for a school project. Overall, we were required to reproduce the behaviour of the function with several flags, conversions, length modifiers ... The only thing I have left to do and that gets…
kRYOoX
  • 397
  • 2
  • 3
  • 10
19
votes
5 answers

WideCharToMultiByte() vs. wcstombs()

What is the difference between WideCharToMultiByte() and wcstombs() When to use which one?
Greenhorn
  • 658
  • 2
  • 8
  • 24
19
votes
3 answers

Displaying wide chars with printf

I'm trying to understand how does printf work with wide characters (wchar_t). I've made the following code samples : Sample 1 : #include #include int main(void) { wchar_t *s; s = (wchar_t…
vmonteco
  • 14,136
  • 15
  • 55
  • 86
10
votes
2 answers

What is the difference between WideChar and AnsiChar?

I'm upgrading some ancient (from 2003) Delphi code to Delphi Architect XE and I'm running into a few problems. I am getting a number of errors where there are incompatible types. These errors don't happen in Delphi 6 so I must assume that this is…
Daisetsu
  • 4,846
  • 11
  • 50
  • 70
10
votes
3 answers

Read wide char from a stream created with fmemopen

I'm trying to read a wide char from a stream that was created using fmemopen with a char *. char *s = "foo bar foo"; FILE *f = fmemopen(s,strlen(s),"r"); wchar_t c = getwc(f); getwc throws a segmentation fault, I checked using GDB. I know this is…
MD XF
  • 7,860
  • 7
  • 40
  • 71
9
votes
1 answer

C++: wide characters outputting incorrectly?

My code is basically this: wstring japan = L"日本"; wstring message = L"Welcome! Japan is "; message += japan; wprintf(message.c_str()); I'm wishing to use wide strings but I do not know how they're outputted, so I used wprintf. When I run…
John D.
  • 265
  • 4
  • 10
7
votes
2 answers

Macro Without Space

I have a macro I use for debugging. #define diagnostic_arg(message,...) fprintf(stderr,message,__VA_ARGS__) I've found that I need to use wide-chars in my program, so I would like to change just my macro and have everything work: #define…
Richard
  • 56,349
  • 34
  • 180
  • 251
7
votes
3 answers

wide version of __FUNCTION__ on linux

is there a way i can print __FUNCTION__ as a wide character on linux? the trick with the WIDEN doesn't work for me, the gcc compiler prints: error: ?L_FUNCTION_? was not declared in this scope any help? Thanks
sramij
  • 4,775
  • 5
  • 33
  • 55
7
votes
1 answer

iostreams - Print `wchar_t` or `charXX_t` value as a character

If you feed a wchar_t, char16_t, or char32_t value to a narrow ostream, it will print the numeric value of the code point. #include using std::cout; int main() { cout << 'x' << L'x' << u'x' << U'x' << '\n'; } prints x120120120. This…
zwol
  • 135,547
  • 38
  • 252
  • 361
7
votes
1 answer

Why there are no "unsigned wchar_t" and "signed wchar_t" types?

The signedness of char is not standardized. Hence there are signed char and unsigned char types. Therefore functions which work with single character must use the argument type which can hold both signed char and unsigned char (this type was chosen…
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
7
votes
4 answers

Use string litterals in a "char type" templated class

I have a template class in C++ which takes as a char_type template parameter the character type, such as char, wchar_t, char32_t, etc... The class then use std::basic_string in the code. Then somewhere in the class I fill a table of…
galinette
  • 8,896
  • 2
  • 36
  • 87
1
2 3
13 14