fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. char* my_strcpy(char** dst, const char* src)
  5. {
  6. *dst = (char *)malloc(sizeof(char)*10); //malloc in function
  7. char* ret= *dst;
  8. while(*ret++ = *src++);
  9. return ret;
  10. }
  11.  
  12.  
  13. void my_str_print(char * my_string)
  14. {
  15. int i;
  16. for( i=0; i<strlen(my_string); i++)
  17. {
  18. printf("%c",my_string[i]);
  19. }
  20. }
  21. int main ()
  22. {
  23. char str1[]="abcde";
  24. char* str2;
  25. printf("the address:%X\n",str2);
  26. my_strcpy(&str2,str1);
  27. my_str_print(str2);
  28. system("PAUSE");
  29. free(str2);
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0.02s 5312KB
stdin
Standard input is empty
stdout
the address:8048470
abcde