fix: examples
This commit is contained in:
@@ -9,15 +9,17 @@ int main(void) {
|
||||
char *c_str;
|
||||
|
||||
/* Allocate a new dynamic string with an initial capacity */
|
||||
/* Always remember to check return values */
|
||||
mcl_string *str = mcl_string_new("Hello, world!", 512);
|
||||
mcl_string_s *str = mcl_string_new("Hello, world!", 512);
|
||||
if (str == NULL) {
|
||||
printf("Failed to initialize string");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Retrieve a C str from mcl_string with mcl_string_cstr() */
|
||||
c_str = mcl_string_cstr(str);
|
||||
length = mcl_string_length(str);
|
||||
capacity = mcl_string_capacity(str);
|
||||
printf("%s\nlength: %ld, capacity: %ld\n", c_str, length, capacity);
|
||||
free(c_str);
|
||||
printf("%s\nlength: %lld, capacity: %lld\n", c_str, length, capacity);
|
||||
|
||||
/* Append text to a mcl_string */
|
||||
mcl_string_append(str, " How are you?");
|
||||
@@ -26,8 +28,7 @@ int main(void) {
|
||||
c_str = mcl_string_cstr(str);
|
||||
length = mcl_string_length(str);
|
||||
capacity = mcl_string_capacity(str);
|
||||
printf("%s\nsize: %ld, cap: %ld\n", c_str, length, capacity);
|
||||
free(c_str);
|
||||
printf("%s\nsize: %lld, cap: %lld\n", c_str, length, capacity);
|
||||
|
||||
/* Always deallocate memory */
|
||||
mcl_string_free(str);
|
||||
|
||||
Reference in New Issue
Block a user