Skip to content

Commit

Permalink
Snippets updated with printf example.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim2266 committed Dec 20, 2020
1 parent e4b9f1e commit 8729120
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,15 @@ Test case and usage example:
str_free(s);
```

##### Using `str` objects with `printf` family of functions

Since a string object is not guaranteed to refer to a null-terminated string it should be formatted
with explicitly specified length, for example:
```C
str s = ...

printf("%.*s\n", (int)str_len(s), str_ptr(s));
```
_Note:_ The maximum length of the string is limited to `INT_MAX` bytes, and formatting will stop
at the first null byte within the string.

0 comments on commit 8729120

Please sign in to comment.