Guest User

Untitled

a guest
Jan 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int main(void)
  5. {
  6.  
  7. char *pSrcString = NULL;
  8. char *pDstString = NULL;
  9.  
  10. /* muppet == 6, so +1 for '' */
  11. if ((pSrcString = malloc(7) == NULL))
  12. {
  13. printf("pSrcString malloc errorn");
  14. return EXIT_FAILURE;
  15. }
  16.  
  17. if ((pDstString = malloc(7) == NULL))
  18. {
  19. printf("pDstString malloc errorn");
  20. return EXIT_FAILURE;
  21. }
  22.  
  23. strcpy(pSrcString,"muppet");
  24.  
  25. strcpy(pDstString,pSrcString);
  26.  
  27. printf("pSrcString= %sn",pSrcString);
  28. printf("pDstString = %sn",pDstString);
  29. free(pSrcString);
  30. free(pDstString);
  31.  
  32. return EXIT_SUCCESS;
  33. }
  34.  
  35. pSrcString = 0;
  36.  
  37. (pSrcString = malloc(7)) == NULL
  38.  
  39. pSrcString = strdup("muppet");
Add Comment
Please, Sign In to add comment