-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.c
53 lines (41 loc) · 1.02 KB
/
example.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#define print(x) fputs((x), stdout)
#define println(x) \
print(x); \
print("\n")
#include "i_string.h"
#include <stdio.h>
void show_data(i_string src, const char* name)
{
printf(
"[%s]\nSize: %zu\nCapacity: %zu\n\n",
name, src -> size, src -> capacity
);
}
int main()
{
/* i_string 'constructor' */
i_string str = IString("Hello", " friend", "!");
/* Copying i_string's */
i_string my_copy = sm.copy(str);
println(str -> content);
println(my_copy -> content);
int arbitrary_value = 5;
/* Formatting */
i_string fstr = sm.format(
"The number %d is now inside of `fstr`",
arbitrary_value
);
/* Appending */
sm.s_append(fstr, ". Nice!\n");
sm.append(fstr, str);
println(fstr -> content);
println("");
show_data(str, "str");
show_data(my_copy, "my_copy");
show_data(fstr, "fstr");
/* Freeing allocated memory */
sm.destroy(my_copy);
sm.destroy(fstr);
sm.destroy(str);
return EXIT_SUCCESS;
}