#include <cstddef>
#include <iostream>
void example_strcpy(char *dest, const char *src)
{
std::size_t i=0;
do
{
dest[i] = src[i];
std::clog << "dest[" << i << "] := '";
if (src[i] == '\0')
std::clog << "\\0' (NUL character)";
else
std::clog << src[i] << '\'';
std::clog << '\n';
}
while (src[i++] != '\0');
}
int main()
{
char name[40];
example_strcpy(name, "Wolverine");
std::cout << "name is: " << name << std::endl;
}
I2luY2x1ZGUgPGNzdGRkZWY+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCnZvaWQgZXhhbXBsZV9zdHJjcHkoY2hhciAqZGVzdCwgY29uc3QgY2hhciAqc3JjKQp7CiAgICBzdGQ6OnNpemVfdCBpPTA7CgogICAgZG8KICAgIHsKICAgICAgICBkZXN0W2ldID0gc3JjW2ldOwogICAgICAgIHN0ZDo6Y2xvZyA8PCAiZGVzdFsiIDw8IGkgPDwgIl0gOj0gJyI7CgogICAgICAgIGlmIChzcmNbaV0gPT0gJ1wwJykKICAgICAgICAgICAgc3RkOjpjbG9nIDw8ICJcXDAnIChOVUwgY2hhcmFjdGVyKSI7CiAgICAgICAgZWxzZQogICAgICAgICAgICBzdGQ6OmNsb2cgPDwgc3JjW2ldIDw8ICdcJyc7CgogICAgICAgIHN0ZDo6Y2xvZyA8PCAnXG4nOwogICAgfQogICAgd2hpbGUgKHNyY1tpKytdICE9ICdcMCcpOwp9CgppbnQgbWFpbigpCnsKICAgIGNoYXIgbmFtZVs0MF07CgogICAgZXhhbXBsZV9zdHJjcHkobmFtZSwgIldvbHZlcmluZSIpOwogICAgc3RkOjpjb3V0IDw8ICJuYW1lIGlzOiAiIDw8IG5hbWUgPDwgc3RkOjplbmRsOwp9Cg==