------------------------------------------------------------------------------
MC logo
String Copy Implementation III
[^] Code Examples
------------------------------------------------------------------------------
<<String Copy Implementation II strcpy3.c Simple String Sort>>
/*
 * A minimalist implementation of strcpy.
 */
char *strcpy(char *target, const char *source)
{
        char *orig_target = target;

        while(*target++ = *source++);

        return orig_target;
}

#include <stdio.h>
int main()
{
        char s1[] = "Hi there, fred!";
        char s2[40];

        strcpy(s2, s1);
        printf("%s\n", s2);
}

This is the most compact version. It is interesting to show off features of the C language, but there is no clear benefit to coding it this way.
Reading: pp. 58-66
<<String Copy Implementation II Simple String Sort>>