Shift part of char array to the same array after encountering a delimiter
C's string implementation is null-terminated. Thus, as long as,


one doesn't care about the original string, (this may not be possible if you have a const char *,) and
one has at least one char that one is willing to discard per block, (usually the block delimiter,) to turn into '\0',


one can do this in place without copying. This tokenizing is very common, and string.h from the standard library has functions that will help. For example, strtok, (and thread-safe extension to the ISO C standard, strtok_r,) or non-standard, but strsep is an improvement, (possible implementation.) In this code, this takes advantage that argv is writable and uses it to come up with some strings which are separated by strchr.

#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;assert.h&gt;

/** One could probably store this, but printing it is easier. */
static void print(const char *p) { printf("codeBuffer &lt;- %s\n", p); }

/** `str0` is a string that get separated by '!'. */
static void str_sep_bang(char *str0, void (*const callback)(const char *)) {
    char *str1;
    assert(str0 &amp;&amp; callback);
    for( ; ; ) {
        if((str1 = strchr(str0, '!'))) *str1 = '\0';
        if(*str0 != '\0') callback(str0);
        if(!str1) break;
        str0 = str1 + 1;
    }
}

int main(int argc, char **argv) {
    int i;
    for(i = 1; i &lt; argc; i++) {
        printf("You passed: %s.\n", argv[i]);
        str_sep_bang(argv[i], &amp;print);
    }
    return 0;
}


This prints out,

bin/stringthing foo\!bar\!baz\!qux \!\!
You passed: foo!bar!baz!qux.
codeBuffer &lt;- foo
codeBuffer &lt;- bar
codeBuffer &lt;- baz
codeBuffer &lt;- qux
You passed: !!.


However, if one needs to store these values, you need space, (an array of char *, same as is passed in argv.) Usually that involves dynamic allocation or static allocation of the maximum size. As well, accessing this list is only valid while the data from the underlying string doesn't change or go out-of-scope; this is why crossing different modules typically involves duplication of the underlying data.