drop math library
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../../string/mystring.h"
|
||||
|
||||
int main(void) {
|
||||
size_t length;
|
||||
size_t capacity;
|
||||
const char *c_str;
|
||||
char *c_str;
|
||||
|
||||
/* Allocate a new dynamic string with an initial capacity */
|
||||
/* Always remember to check return values */
|
||||
@@ -16,6 +17,7 @@ int main(void) {
|
||||
length = mcl_string_length(str);
|
||||
capacity = mcl_string_capacity(str);
|
||||
printf("%s\nlength: %ld, capacity: %ld\n", c_str, length, capacity);
|
||||
free(c_str);
|
||||
|
||||
/* Append text to a mcl_string */
|
||||
mcl_string_append(str, " How are you?");
|
||||
@@ -25,6 +27,7 @@ int main(void) {
|
||||
length = mcl_string_length(str);
|
||||
capacity = mcl_string_capacity(str);
|
||||
printf("%s\nsize: %ld, cap: %ld\n", c_str, length, capacity);
|
||||
free(c_str);
|
||||
|
||||
/* Always deallocate memory */
|
||||
mcl_string_free(str);
|
||||
|
||||
20
examples/string/str2.c
Normal file
20
examples/string/str2.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../../string/mystring.h"
|
||||
|
||||
int main(void) {
|
||||
mcl_string *str = mcl_string_new("Hello, world!", 0);
|
||||
mcl_string_append(str, " How are you?");
|
||||
|
||||
char *c_str = mcl_string_cstr(str);
|
||||
size_t len = mcl_string_length(str);
|
||||
size_t cap = mcl_string_capacity(str);
|
||||
|
||||
fprintf(stdout, "%s\nlen: %ld\ncapacity: %ld\n", c_str, len, cap);
|
||||
|
||||
mcl_string_free(str);
|
||||
free(c_str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user