From f5608395161d28d9bcd3ef2aaf543299c6fdbddf Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 10 Jan 2021 09:51:53 +0100 Subject: [PATCH] Add example of string_sets --- example/ex-string02.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/example/ex-string02.c b/example/ex-string02.c index debfb6d8..a427d7bd 100644 --- a/example/ex-string02.c +++ b/example/ex-string02.c @@ -63,6 +63,13 @@ static void main_macro(void) str_array_push_back(tab_name, format); string_printf(format, "The third element is '%s'", string_get_cstr(*str_array_get(tab_name, 2))); str_array_push_back(tab_name, format); +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + // Set format to a formated string + // In C11, we can mix string_t and char *. + // We can also use M_CSTR to create a printf formated string. + string_sets(format, "FILE=", getenv("PWD"), "/", *str_array_get(tab_name, 2), M_CSTR("-%d.txt", str_array_size(tab_name) )); + str_array_push_back(tab_name, format); +#endif } // beyond this point format is cleared // Display the content of the array.