Guest User

Untitled

a guest
Jul 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. char *command = "nest";
  2. char *halloween = join("hallowee", command[0]); //this gives an error
  3.  
  4. char *join(const char* s1, const char* s2)
  5. {
  6. char* result = malloc(strlen(s1) + strlen(s2) + 1);
  7.  
  8. if (result)
  9. {
  10. strcpy(result, s1);
  11. strcat(result, s2);
  12. }
  13.  
  14. return result;
  15. }
  16.  
  17. char *join(const char* s1, const char c)
  18. {
  19. int len = strlen(s1);
  20. char* result = malloc(len + 2);
  21.  
  22. if (result)
  23. {
  24. strcpy(result, s1);
  25. result[len] = c; //add the extra character
  26. result[len+1] = ''; //terminate the string
  27. }
  28.  
  29. return result;
  30. }
  31.  
  32. char *command = "nest";
  33. char *buffer = " "; // one space and an implicit trailing ''
  34. char *halloween;
  35.  
  36. *buffer = command[0];
  37. halloween = join("hallowee", buffer);
Add Comment
Please, Sign In to add comment