...
The managed string library is based on a dynamic approach in that memory is allocated and reallocated as required. This approach eliminates the possibility of unbounded copies, NULLnull-termination errors, and truncation by ensuring there is always adequate space available for the resulting string (including the terminating NULL character).
...
The following code illustrates how the managed string library can be used to create a managed string and retrieve a NULLnull-terminated byte string from the managed string.
Code Block |
---|
errno_t retValue; char *cstr; /* pointer to NULL null- terminated byte string */ string_m str1 = NULL; if (retValue = strcreate_m(&str1, "hello, world", 0, NULL)) { fprintf(stderr, "Error %d from strcreate_m.\n", retValue); } else { /* retrieve NULL null- terminated byte string and print */ if (retValue = getstr_m(&cstr, str1)) { fprintf(stderr, "error %d from getstr_m.\n", retValue); } printf("(%s)\n", cstr); free(cstr); /* free NULL null- terminated byte string */ } |
...