////////////////////////////////////////
#include
////////////////////////////////////////
// The first version of string_copy().
////////////////////////////////////////
void string_copy(char *dest, const char* src)
{
    while((*dest++ = *src++) != '\0')
        ;
}
////////////////////////////////////////
// The second version of string_copy().
////////////////////////////////////////
void string_copy(char* dest, const char* src, int len)
{
    while (len && (*dest++ = *src++) != '\0')
        --len;
    while (len--)
        *dest++ = '\0';
}
char misspiggy[20], kermit[20];
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
main()
{
    string_copy(misspiggy, "Miss Piggy");
    string_copy(kermit,
        "Kermit, the file transfer protocol", 6);
    std::cout << kermit << " and " << misspiggy;
}

Like it on Facebook, Tweet it or share this article on other bookmarking websites.

No comments