Created
November 23, 2013 19:42
-
-
Save gcr/7618994 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "stdio.h" // includes definiton of printf | |
| #include "stdlib.h" // includes definiton of malloc | |
| void copy_string(char *dest, char *src) { | |
| // Copy bytes from src into dest | |
| while ((*(dest++) = *(src++))) {}; | |
| } | |
| int main(){ | |
| char *hello_msg = "Hello, World!"; | |
| char *dest = malloc(30); | |
| // Returns a pointer to 30 bytes of free space somewhere in memory | |
| char *yourname = "Elamind!"; | |
| printf("%s\n", dest); | |
| copy_string(dest, hello_msg); | |
| printf("%s\n", dest); | |
| copy_string(dest+7, yourname); | |
| printf("%s\n", dest); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment