refactor: improve string methods
This commit is contained in:
@@ -51,7 +51,7 @@ int main(void) {
|
||||
/* This hashmap will contain names as keys and a custom type as value */
|
||||
size_t key_size = sizeof(char) * MAX_STR_LEN;
|
||||
size_t value_size = sizeof(int) + sizeof(char) * MAX_STR_LEN;
|
||||
mcl_hashmap_s *map = mcl_hm_init(my_hash_func, my_equal_fun, my_free_key, my_free_value, key_size, value_size);
|
||||
mcl_hashmap_s *map = mcl_hm_new(my_hash_func, my_equal_fun, my_free_key, my_free_value, key_size, value_size);
|
||||
|
||||
/* Set a new value */
|
||||
struct my_custom_type p1 = {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
int main(void) {
|
||||
/* Allocate a new queue */
|
||||
/* Always remember to check return values */
|
||||
mcl_queue_s *queue = mcl_queue_init(3, sizeof(int));
|
||||
mcl_queue_s *queue = mcl_queue_new(3, sizeof(int));
|
||||
|
||||
int val, out;
|
||||
|
||||
|
||||
31
examples/string/str2.c
Normal file
31
examples/string/str2.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../string/mystring.h"
|
||||
|
||||
int main(void) {
|
||||
mcl_string_s *s1 = mcl_string_new("Hello, world!", 0);
|
||||
mcl_string_s *s2 = mcl_string_new("Hello, world!", 0);
|
||||
|
||||
/* Dont' call mcl_string_cstr() more than once in the same printf function */
|
||||
printf("s1: %s\n", mcl_string_cstr(s1));
|
||||
printf("s2: %s\n", mcl_string_cstr(s2));
|
||||
|
||||
int ret = mcl_string_compare(s1, s2);
|
||||
if (ret == 0) {
|
||||
printf("Same string!\n");
|
||||
}
|
||||
|
||||
mcl_string_clear(s1);
|
||||
if (mcl_string_compare(s1, s2) != 0) {
|
||||
printf("Not the same!\n");
|
||||
}
|
||||
|
||||
mcl_string_toupper(s1);
|
||||
mcl_string_tolower(s2);
|
||||
|
||||
printf("s1: %s\n", mcl_string_cstr(s1));
|
||||
printf("s2: %s\n", mcl_string_cstr(s2));
|
||||
|
||||
mcl_string_free(s1);
|
||||
mcl_string_free(s2);
|
||||
}
|
||||
Reference in New Issue
Block a user