Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a format specifier that always means char string with _tprintf?

When you build an app on Windows using TCHAR support, %s in _tprintf() means char * string for Ansi builds and wchar_t * for Unicode builds while %S means the reverse.

But are there any format specifiers that always mean char * string no matter if it's an Ansi or Unicode build? Since even on Windows UTF-16 is not really used for files or networking it turns out to still be fairly often that you'll want to deal with byte-based strings regardless of the native character type you compile your app as.

like image 245
hippietrail Avatar asked Apr 14 '11 20:04

hippietrail


People also ask

What does %I mean in C?

%i takes integer value as integer value with decimal, hexadecimal or octal type.

What is %s in C?

%s is for string %d is for decimal (or int) %c is for character.

Is a format specifier used for string?

The Format specifier is a string used in the formatted input and output functions. The format string determines the format of the input and output. The format string always starts with a '%' character.


2 Answers

The h modifier forces both %s and %S to char*, and the l modifier forces both to wchar_t*, ie: %hs, %hS, %ls, and %lS.

like image 66
Remy Lebeau Avatar answered Sep 24 '22 10:09

Remy Lebeau


This might also solve your problem:

_TCHAR *message;
_tprintf(_T("\n>>>>>> %d") TEXT(" message is:%s\n"),4,message);
like image 36
RKum Avatar answered Sep 25 '22 10:09

RKum