3

What is the meaning of the format control specifier "%S\%016I64X%S" in this sprintf_s command ?

As far as I know, it defines a string which converts numbers to unsigned 64 bit integer in Hexadecimal format. I would like to know whether I am right ? Please help me..

char lFileName[MAX_PATH];
sprintf_s( lFileName, MAX_PATH, "%S\\%016I64X%S", mSavePath.GetBuffer(),aBuffer->GetTimestamp(), lExt );
Robionic
  • 315
  • 4
  • 14

1 Answers1

4

First, it looks like a Visual C++ usage of

int sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);

The format consists of multiple directives: "%S", "\\", "%016I64X", "%S".

"%S" "When used with printf functions, specifies a wide-character string; ..." more

"\\" is simply a \.

"%016I64X" is an X format specifier of hexadecimal output. 0 to indicate zero-filling as needed. 16 to indicate the minimum output length. I64 is a windows specific modifier indicating the expected integer is of windows specific type unsigned __int64. more

You are on the right track with "unsigned 64 bit integer".

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
  • Why not `%uud`? :D – hola Sep 24 '18 at 20:59
  • @pushpen.paul Re: [Why not `%uud`](https://stackoverflow.com/questions/18123066/what-is-the-meaning-of-the-format-control-specifier-016i64x-in-sprintf-s/18429938?noredirect=1#comment91915809_18429938): `"%uud"` is C standard `"%u"` followed by `"ud"`. Perhaps you are thinking of `"%llu"`? IAC, an implementation type `unsigned __int64` could map to standard types `unsigned long`, `unsigned long long` or others and then use `"%llX"`, `"%lX"` to print hex. Using C99 specifiers, like `"%" PRIX64` makes most sense via [``](https://stackoverflow.com/a/1156285/2410359). – chux - Reinstate Monica Sep 24 '18 at 21:46