copy string
Definition
char *copy_string(char *dest, char *source);
Description
Copy source into dest.
Parameters
- dest
- Destination string where the resource string should be overwritten.
- source
- Source of what should be copied.
Return Value
On success, this functions returns dest, which could be pointing to a new memory location.
If the function fails, dest is returned.
Example
#include <stdio.h> #include <libc/string.h> int main(int argc, char *argv[]) { char *original_string = create_string("Hello "); char *new_string = create_string("world!"); original_string = copy_string(original_string, new_string); printf("Original string: %s\n", original_string); free(new_string); free(original_string); return 0; }
Original string: world!