format-specifiers

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

天涯浪子 提交于 2019-12-23 09:09:51
问题 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

mingw printf size specification character h

别等时光非礼了梦想. 提交于 2019-12-23 03:55:08
问题 Visual Studio has a size and distance specification chart that says I can do something like this, using the h prefix to specify single byte character string regardless of printf or wprintf: int main() { char test[]= "abc"; _tprintf(_T("%hs\n"),test); } But if I compile the same thing with mingw gcc and -Wall I get the following warning: warning: format '%hs' expects type 'short int *', but argument 2 has type 'char *' Is what I'm doing an acceptable way to specify a single byte character

Why is the format specifier for uint8_t and uint16_t the same (%u)? [duplicate]

对着背影说爱祢 提交于 2019-12-21 07:56:47
问题 This question already has an answer here : What default promotions of types are there in the variadic arguments list? (1 answer) Closed 5 years ago . I only found pretty unrelated questions due to the tons of results searching for printf() . Why does uint8_t not specify its own format string but any other type does? As far as I understand printf() , it has to know the length of the supplied parameters to be able to parse the variable argument list. Since uint8_t and uint16_t use the same

Scanning with %c or %s

落爺英雄遲暮 提交于 2019-12-17 22:03:35
问题 I had to do a program for college in which I should separate, between a certain amount of people, those who liked and the ones who disliked something. so I did this: char like[100]; printf("Like? Y or N \n"); scanf ("%c", like); The program compiled, but didn't work the way it should. The user was not able to write "y or n" when asked "Like?" So I tried this: char like[100]; printf("Like? Y or N \n"); scanf ("%s", like); And it worked. But I don't know why it worked. Can somebody please

What does the %*s format specifier mean?

懵懂的女人 提交于 2019-12-17 17:29:43
问题 In some code that I have to maintain, I have seen a format specifier %*s . Can anybody tell me what this is and why it is used? An example of its usage is like: fprintf(outFile, "\n%*s", indent, ""); 回答1: It's used to specify, in a dynamic way, what the width of the field is: The width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted. so "indent" specifies how much space to allocate for the string that follows

What precisely does the %g printf specifier mean?

核能气质少年 提交于 2019-12-17 16:36:18
问题 The %g specifier doesn't seem to behave in the way that most sources document it as behaving. According to most sources I've found, across multiple languages that use printf specifiers, the %g specifier is supposed to be equivalent to either %f or %e - whichever would produce shorter output for the provided value. For instance, at the time of writing this question, cplusplus.com says that the g specifier means: Use the shortest representation: %e or %f And the PHP manual says it means: g -

can there be less number of fomat specifier than the number of variables in a printf statement

痞子三分冷 提交于 2019-12-14 02:48:00
问题 I have coded the following program in a borland c compiler.My doubt is why c compiler doesnot throw any error neither in compile time or run time.The program executes fine and the output is 2 4. #include<stdio.h> #include<conio.h> int main(){ int a=2,b=4,c=6; printf("%d%d",a,b,c); getch(); return 0; } Even though there are less no of format specifiers than the number of arguments there is no error thrown.What is happening here. 回答1: can there be less number of fomat specifier than the number

Format specifiers for data type BYTE, WORD and DWORD in c-language?

五迷三道 提交于 2019-12-13 12:17:34
问题 In C-language, what are the most appropriate format specifiers for data type BYTE, WORD and DWORD to be used with printf and scanf functions? I am having a hard time displaying BPB field's values over console. For example, if I am trying to display BPB_BytsPerSec using "%lu", I am getting unusual figures.. printf("Bytes per Sector: %lu", b->BPB_BytsPerSec); I am getting a value of "514", which I believe, is wrong interpretation.. Please suggest the way out. Thanks. (I am using gcc 5.1 via

printing int using %f format specifier [duplicate]

不羁岁月 提交于 2019-12-13 09:39:59
问题 This question already has answers here : Unexpected output of printf (4 answers) Closed 4 years ago . I wanted to know why output is coming as 0.000000. I know printing int using float format specifier or using a type of value using b type gives unspecified behaviour as written in many place. I'm quoting it "If a conversion specification is invalid, the behaviour is undefined. If any argument is not the correct type for the corresponding conversion specification, the behaviour is undefined."

Validating an email address with sscanf() format specifiers

China☆狼群 提交于 2019-12-13 01:34:02
问题 This may be somewhat of a "fix-my-code" question, but I've looked at documentation, examples, and dozens, of, related, questions, and though I logically understand more or less how it all works, I am having trouble translating it into a C sscanf() format code. I am still relatively new to C, and am just starting to get into slightly beyond-simplistic stuff, and I am having trouble figuring out more complex format specifiers (ie. %[^...] , etc.). Anyways, here's what I have: char user[EMAIL