Difference between revisions of "Prokee Module: mstr"
Jump to navigation
Jump to search
(→Example) |
|||
| Line 2: | Line 2: | ||
== Example == | == Example == | ||
| − | + | <syntaxhighlight lang="C"> | |
| − | + | mstrs<char> *a; | |
| − | + | mstr::create(&a,10); // initial memory allocation of 10 Bytes | |
| − | + | mstr::copy_str(a,"Hello World!"); // copying of a string (allocates a larger memory block for 'a') | |
| − | + | printf("%s\n",mstr::c_str(a)); | |
| + | mstr::destroy(a); // frees all memory allocated for 'a' | ||
| + | </syntaxhighlight> | ||
== Implementations == | == Implementations == | ||
Latest revision as of 13:29, 12 June 2019
The module mstr provides basic functionality for strings (like copying, concatenation and comparison) with automated reallocation of larger memory blocks, if required.
Example
mstrs<char> *a;
mstr::create(&a,10); // initial memory allocation of 10 Bytes
mstr::copy_str(a,"Hello World!"); // copying of a string (allocates a larger memory block for 'a')
printf("%s\n",mstr::c_str(a));
mstr::destroy(a); // frees all memory allocated for 'a'