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.

180 questions
36
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
  • 189,354
  • 112
  • 476
  • 821
36
votes
7 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
  • 1,744
  • 5
  • 21
  • 32
30
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
  • 1,927
  • 3
  • 24
  • 45
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

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
  • 775
  • 2
  • 6
  • 17
15
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
  • 337
  • 3
  • 10
12
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
  • 10,994
  • 12
  • 43
  • 73
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,416
  • 9
  • 46
  • 68
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,062
  • 7
  • 34
  • 64
8
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.
  • 255
  • 4
  • 10
7
votes
5 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
  • 7,938
  • 29
  • 73
7
votes
2 answers

wprintf: %p with NULL pointer

As I was writing a unit test, I stumbled upon some odd behavior from glibc, regarding "%p" and the NULL pointer. If I have a line such as printf("NULL pointer is %p\n", NULL);, then I see NULL pointer is (nil) printed to the screen, as I…
Drew McGowen
  • 10,984
  • 1
  • 27
  • 55
6
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
  • 44,865
  • 24
  • 144
  • 216
6
votes
1 answer

Why is © (the copyright symbol) replaced with (C) when using wprintf?

When I try to print the copyright symbol © with printf or write, it works just fine: #include int main(void) { printf("©\n"); } #include int main(void) { write(1, "©\n", 3); } Output: © But when I try to print it…
S.S. Anne
  • 13,819
  • 7
  • 31
  • 62
6
votes
2 answers

_T( ) macro changes for UNICODE character data

I have UNICODE application where in we use _T(x) which is defined as follows. #if defined(_UNICODE) #define _T(x) L ##x #else #define _T(x) x #endif I understand that L gets defined to wchar_t, which will be 4 bytes on any platform. Please correct…
Nagasai Sowmya
  • 201
  • 2
  • 3
  • 4
1
2 3
11 12