String Copy in C
Level 4172 keystrokes
Implements a string copy function using pointers.
C code
// Copy string from src to dest1void str_copy(char *dest, const char *src) { // Loop until null terminator2 while (*src != '\0') { // Copy one char, then advance both pointers (postfix ++)3 *dest++ = *src++;4 } // The loop skips the terminator, so add it to dest5 *dest = '\0';6}7 // Destination buffer, large enough for "Hello" plus '\0'8char buffer[20];// Copy "Hello" to buffer9str_copy(buffer, "Hello");// Prints Hello10printf("%s\n", buffer);Output
Hello
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
*× 6;× 5'× 4"× 4(× 4)× 4+× 4,× 3\× 3=× 3