It's an old question, I hope you have already found a useful one. In case you didn't, please check out the Simple Dynamic String library on github. I copy&paste the author's description here:

SDS is a string library for C designed to augment the limited libc string handling functionalities by adding heap allocated strings that are:

  • Simpler to use.
  • Binary safe.
  • Computationally more efficient.
  • But yet... Compatible with normal C string functions.

This is achieved using an alternative design in which instead of using a C structure to represent a string, we use a binary prefix that is stored before the actual pointer to the string that is returned by SDS to the user.

+--------+-------------------------------+-----------+
| Header | Binary safe C alike string... | Null term |
+--------+-------------------------------+-----------+
         |
         `-> Pointer returned to the user.

Because of meta data stored before the actual returned pointer as a prefix, and because of every SDS string implicitly adding a null term at the end of the string regardless of the actual content of the string, SDS strings work well together with C strings and the user is free to use them interchangeably with real-only functions that access the string in read-only.

Answer from Steinway Wu on Stack Overflow
🌐
W3Schools
w3schools.com › c › c_ref_string.php
C string (string.h) Library Reference
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate ... The <string.h> library has many functions that allow you to perform tasks on strings.
Top answer
1 of 6
47

It's an old question, I hope you have already found a useful one. In case you didn't, please check out the Simple Dynamic String library on github. I copy&paste the author's description here:

SDS is a string library for C designed to augment the limited libc string handling functionalities by adding heap allocated strings that are:

  • Simpler to use.
  • Binary safe.
  • Computationally more efficient.
  • But yet... Compatible with normal C string functions.

This is achieved using an alternative design in which instead of using a C structure to represent a string, we use a binary prefix that is stored before the actual pointer to the string that is returned by SDS to the user.

+--------+-------------------------------+-----------+
| Header | Binary safe C alike string... | Null term |
+--------+-------------------------------+-----------+
         |
         `-> Pointer returned to the user.

Because of meta data stored before the actual returned pointer as a prefix, and because of every SDS string implicitly adding a null term at the end of the string regardless of the actual content of the string, SDS strings work well together with C strings and the user is free to use them interchangeably with real-only functions that access the string in read-only.

2 of 6
14

I would suggest not using any library aside from malloc, free, strlen, memcpy, and snprintf. These functions give you all of the tools for powerful, safe, and efficient string processing in C. Just stay away from strcpy, strcat, strncpy, and strncat, all of which tend to lead to inefficiency and exploitable bugs.

Since you mentioned searching, whatever choice of library you make, strchr and strstr are almost certainly going to be what you want to use. strspn and strcspn can also be useful.

Discussions

Str: Yet another string library for C language
Every library like this is incompatible and most make slightly odd choices like in this library ownership of the string is denoted by a bit in the info/size field. Not that that is a bad choice or anything, but it is one reason someone might decline to use it and decide to write their own · ... More on news.ycombinator.com
🌐 news.ycombinator.com
95
82
November 27, 2020
Decent string lib for C? | Handmade Network
The downside to some of the other languages though is loss of power so I really would consider making some of these tools in C if I had access to better libraries that could help me get more done. ... From simpler, single/two file libraries: Simple Dynamic Strings Better String Library A bit ... More on handmade.network
🌐 handmade.network
October 12, 2018
What are the most commonly used & useful string functions in C?
printf and it's variants are among the most used and useful string functions that I use. If we're counting other functions in string.h I'd definitely add memset and memcpy. More on reddit.com
🌐 r/C_Programming
54
55
May 4, 2024
GitHub - pmkenned/pmk_string: A simple string library in C
Partly for practice, partly for fun, and partly because most of the string libraries I was finding online are orders of magnitude larger than I wanted, I wrote a tiny string handling library in C. It's a work in progress, but I believe it is mostly bug-free and compiles using gcc, clang, and msvc. Feedback welcome. More on reddit.com
🌐 r/C_Programming
41
11
December 27, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-library-string-h
C Library - <string.h> - GeeksforGeeks
July 23, 2025 - string.h is a standard header file in the C language that contains functions for manipulating strings (arrays of characters).
🌐
Hacker News
news.ycombinator.com › item
Str: Yet another string library for C language | Hacker News
November 27, 2020 - Every library like this is incompatible and most make slightly odd choices like in this library ownership of the string is denoted by a bit in the info/size field. Not that that is a bad choice or anything, but it is one reason someone might decline to use it and decide to write their own · ...
🌐
TutorialsPoint
tutorialspoint.com › home › c_standard_library › c standard library string functions
C Standard Library String Functions
August 29, 2012 - Discover the essential string functions in the C Standard Library, with examples and detailed usage to enhance your C programming skills.
🌐
Cplusplus
cplusplus.com › reference › cstring
<cstring> (string.h)
C Strings This header file defines several functions to manipulate C strings and arrays.
Find elsewhere
🌐
Handmade Network
handmade.network › forums › t › 3451-decent_string_lib_for_c
Decent string lib for C? | Handmade Network
October 12, 2018 - The downside to some of the other languages though is loss of power so I really would consider making some of these tools in C if I had access to better libraries that could help me get more done. ... From simpler, single/two file libraries: Simple Dynamic Strings Better String Library A bit more header files, but more functionality: µstr - Micro String API For more universal strings (supports full unicode), but much more heavier: ICU
🌐
GitHub
github.com › maxim2266 › str
GitHub - maxim2266/str: str: yet another string library for C language.
str: yet another string library for C language. Contribute to maxim2266/str development by creating an account on GitHub.
Starred by 351 users
Forked by 26 users
Languages   C 98.6% | Makefile 1.4%
🌐
GNU
gnu.org › software › libc › manual › html_node › String-and-Array-Utilities.html
String and Array Utilities (The GNU C Library)
Operations on strings (null-terminated byte sequences) are an important part of many programs. The GNU C Library provides an extensive set of string utility functions, including functions for copying, concatenating, comparing, and searching strings.
🌐
cppreference.com
en.cppreference.com › w › c › header › string.html
Standard library header <string.h>
March 12, 2025 - #define __STDC_VERSION_STRING_H__ 202311L #define NULL /* see description */ typedef /* see description */ size_t; void* memcpy(void* restrict s1, const void* restrict s2, size_t n); void* memccpy(void* restrict s1, const void* restrict s2, int c, size_t n); void* memmove(void* s1, const void* s2, size_t n); char* strcpy(char* restrict s1, const char* restrict s2); char* strncpy(char* restrict s1, const char* restrict s2, size_t n); char* strdup(const char* s); char* strndup(const char* s, size_t n); char* strcat(char* restrict s1, const char* restrict s2); char* strncat(char* restrict s1, con
🌐
W3Schools
w3schools.com › cpp › cpp_ref_cstring.asp
C++ cstring Library Reference (cstring functions)
C++ Reference C++ Keywords C++ ... C++ Study Plan C++ Certificate ... The <cstring> library has many functions that allow you to perform tasks on arrays and C-style strings....
🌐
Cppreference
en.cppreference.com › w › cpp › header › cstring.html
Standard library header <cstring>
February 9, 2025 - This header was originally in the C standard library as <string.h>.
🌐
Sdds
intro2c.sdds.ca › string library
String Library | Introduction to C
The standard library that ships with C compilers and processes character strings is called the string library.
🌐
Linux Man Pages
man7.org › linux › man-pages › man3 › string.3.html
string(3) - Linux manual page
string(3) Library Functions Manual string(3) stpcpy, strcasecmp, strcat, strchr, strcmp, strcoll, strcpy, strcspn, strdup, strfry, strlen, strncat, strncmp, strncpy, strncasecmp, strpbrk, strrchr, strsep, strspn, strstr, strtok, strxfrm, index, rindex - string operations · Standard C library (libc, -lc) #include <strings.h> strcasecmp(3) Compare two strings, ignoring case.
🌐
Reddit
reddit.com › r/c_programming › github - pmkenned/pmk_string: a simple string library in c
r/C_Programming on Reddit: GitHub - pmkenned/pmk_string: A simple string library in C
December 27, 2022 - Partly for practice, partly for fun, and partly because most of the string libraries I was finding online are orders of magnitude larger than I wanted, I wrote a tiny string handling library in C. It's a work in progress, but I believe it is mostly bug-free and compiles using gcc, clang, and msvc.
🌐
GNU
ftp.gnu.org › old-gnu › Manuals › glibc-2.2.3 › html_chapter › libc_5.html
The GNU C Library - String and Array Utilities
Operations on strings (or arrays of characters) are an important part of many programs. The GNU C library provides an extensive set of string utility functions, including functions for copying, concatenating, comparing, and searching strings.
🌐
Reddit
reddit.com › r/c_programming › my own c string library.
r/C_Programming on Reddit: My own c string library.
July 30, 2024 -

This was my weekend project.

This was just to have fun and learn and also, play with C.

I am working in another personal project, and need to use string.

This was based from: https://github.com/antirez/sds and https://github.com/mauro-balades/ultimate-string-library (https://www.reddit.com/r/C_Programming/comments/16hy3zv/my_own_take_on_making_a_new_c_string_library_is/)

I took the idea of the string length from Base128 encoding techniques, actually my first take I implemented a encoder and decoder, however I dropped in favor of something simpler

Basically, the first byte its the options.

I have an bitfield structure, where the first 3 bits, represent the string length in bytes. Maximum its 8 bytes(a lot of bytes)

THe next bit its to inform if the string its updatable(I would like to implement some memory protection later)

The next two bits, represent the encoding(ascii, utf8, utf16 and utf-32), I havent implemented this yet.

2 bits are reserved, maybe I will use this to set the library version, So, it can be compatible with later version where I reorder the 2th byte for example to be the last.

The following bytes, are the string length. If the string size its less than 256, we are going to use only one byte.

Lets say that we requested memory 7 bytes for the OS, and it returned the **region** `0x4052a0` to us.Lets say that we requested memory 7 bytes for the OS, and it returned the **region** `0x4052a0` to us.

Memory RegionValue
0x4052A00x09
0x4052A10x01
0x4052A20x48('H')
0x4052A30x65('e')
0x4052A40x6C('l')
0x4052A50x6C('l')
0x4052A60x6F('o')

Github: https://github.com/sgtcortez/SimpleCompactString

Thank you

🌐
Reddit
reddit.com › r/c_programming › do we need to add a string library if we want to use string data type?
r/C_Programming on Reddit: Do we need to add a string library if we want to use string data type?
November 16, 2024 - There is no string data type in C , a string is simply an array if characters that ends with null character '/0'. You can declare it as char[] (array) or char* ( a pointer to the first character) ...
🌐
GeeksforGeeks
geeksforgeeks.org › c language › strings-in-c
Strings in C - GeeksforGeeks
November 14, 2025 - We can change individual characters of a string using their index: str[0] = 'h'. Strings can also be updated using standard library functions like strcpy() to replace the entire string.