Copying a program name
#include <string.h> size_t const len = strlen(argv[0]); char name[len+1]; memcpy(name, argv[0], len); name[len] = 0; if (!strcmp(name, argv[0])) printf("successfully copied\n");
string.h declares standard-library functions for manipulating character arrays and null-terminated strings. Names beginning with mem operate on arrays; names beginning with str require strings. section 6.1.5
The interfaces divide into two practical groups:
- memcpy copies a specified number of characters between known-distinct arrays; memcmp compares array prefixes; memchr searches an array. section 6.1.5
- strlen finds the first zero character, strcpy copies a zero-terminated source, and strcmp compares two strings lexicographically. section 6.1.5
- A string argument must be zero-terminated, and a strcpy destination must be large enough for the copied string and its terminator. section 6.1.5

