Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char *copy_string(char *p)
- {
- char *copy = (char*)malloc(sizeof(char) * (strlen(p)+1));
- if(copy = NULL)
- exit(1);
- strcpy(copy,p);
- return copy;
- }
- int main()
- {
- char string[] = "Hello World!";
- char *new_string = copy_string(string);
- puts(new_string);
- free(new_string);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement