sub string
Definition
char *sub_string(char *string, size_t offset, size_t len);
Description
Create a new string based on part of the source string
Parameters
- string
- Source string.
- offset
- Offset position of which the source string is selected.
- len
- Length of the part which should be selected.
If len is 0 the total length of the string is selected.
Return Value
On success, this functions returns a newly created string which is based partially on string.
If the function fails, a NULL pointer is returned.
Example
#include <stdio.h> #include <libc/string.h> int main(int argc, char *argv[]) { char *original_string = create_string("Hello World!"); char *new_string = sub_string(original_string, 1, 3); printf("New String: %s\n", new_string); free(new_string); free(original_string); return 0; }
Output:
New String: ell