Skip to content

Instantly share code, notes, and snippets.

@gcr
Created November 23, 2013 19:42
Show Gist options
  • Select an option

  • Save gcr/7618994 to your computer and use it in GitHub Desktop.

Select an option

Save gcr/7618994 to your computer and use it in GitHub Desktop.
#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