SMARTSTR.H is a library that provides an interface to work with text strings as in common high-level programming languages. SMARTSTR.H stands for "SMART Strings Header file"
- Fast and efficient.
- Easy to use.
- Works on any C version starting from C99.
- Doesn't require any dependencies besides the standard library.
To create a string, just use the str_new()
function.
#include <smartstr.h>
int main(void){
String str = str_new();
//More code here...
}
Strings in SMARTSTR.H have only two members: A value
, and a length
. This is because a String
is essentially a struct
:
typedef struct String{
char *value;
size_t length;
} String;
Note: The length
member always includes the null character (\0
). So, if you do this:
#include <smartstr.h>
int main(void){
String str1 = str_new();
str_ccopy(&str1, "Hello World!");
//More code here...
}
The member str1.length
will have a value of 13
instead of 12
, as str.value
= Hello World!\0
.
Whenever you're finished using a String, don't forget to str_free()
it to prevent memory leaks!
str_free(&str1);
Please read SMARTSTR.H Reference.
Thanks so much to all of our contributors.