Ad
  • Custom User Avatar

    Not sure, but I think may be the fifth(last part of string) %d holds the 'end of the string character (or so called null termination) "\0"'.

  • Custom User Avatar

    I tested it. The code works with or without the very last %d. It was probably placed there by mistake.

  • Default User Avatar

    I've never even heard of snprintf
    But I must admit that the solution is pretty to read.
    Though I must ask about the fifth "%d" in the last part of the string. Why is that there?

  • Default User Avatar

    I was pleasantly surprised to see that the solution I thought would be considered an inefficient "naive" approach seems to be a pretty popular one, since I seem to be unfamiliar with advanced string manipulation/creation in C++.
    Mine is pretty much the same, just with some minor formatting differences