Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Thanks! I think I like Alternative 3 best as well. However I want to be able to do things like: printf("MyType: %s\n", mytype_to_string( mt, buf, sizeof(buf)); and hence I won't like to return the length used but rather the pointer to the string. The dynamic library comment is really important. Commented Feb 8, 2015 at 10:34
  • Shouldn't this be sizeof(buffer) - 1 to satisfy the \0 terminator? Commented Nov 9, 2016 at 12:27
  • 1
    @Michael-O no the null term is included in the buffer size meaning that the max string that can be put in is 1 less than the passed in size. This is the pattern that the safe string functions in the standard library like snprintf use. Commented Nov 9, 2016 at 12:51
  • @ratchetfreak Thanks for clarification. Would be nice to extend the answer with that wisdom. Commented Nov 9, 2016 at 13:34