Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 948 Bytes

README.md

File metadata and controls

45 lines (32 loc) · 948 Bytes

str

A simple library to do string manipulation in C.

str simplifies working with strings in C and targets simplicity as one of its goals.

Example: Checking palindromes

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.