// One way to implement the standard strcpy() function.
char *strcpy(char *target, const char *source) {
char *t = target;
// Copy the contents of source into target.
while(*source) *target++ = *source++;
// Null-terminate the target.
*target = '\0';
// Return pointer to the start of target.
return t;
}
Pay special attention to this line:
while(*source) *target++ = *source++;
0 comments:
Post a Comment