str simplifies working with strings in C and targets simplicity as one of its goals.
The following program checks whether words passed to it are palindromes or not. It is a rather simple example but it shows some of the library features.
/* ... */
#include "str.h"
void is_palindrome(char const* s) {
str* word = str_from(s);
str* reversed = str_clone(word);
str_reverse(reversed);
printf("%s is %sa palindrome!\n",
str_cstr(word),
str_equal(word, reversed)
? ""
: "not ");
str_del(reversed);
str_del(word);
}
int main(int argc, char const** argv) {
/* ... */
for (int i = 1; i < argc; ++i) {
is_palindrome(argv[i]);
}
/* ... */
}
You can see the full example under docs/examples
. More code
snippets will be added in the future.