Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. char *_strncat(char *dest, char *src, int n)
  2. {
  3. char *ret = dest;
  4. while (*dest) /* same as: while (dest[0] !- '') */
  5. {
  6. dest++; /* w. each loop, array is shifted left until it's empty */
  7. }
  8. while (n != 0)
  9. {
  10. if (!(*dest++ = *src++)) /* <=========here */
  11. return ret;
  12. n--;
  13. }
  14. *dest = 0;
  15. return (ret);
  16. }
  17.  
  18. if (!(*dest++ = *src++))
  19. return;
  20.  
  21. char temp1 = *src++; // copy from *src to temp1 and increment src
  22. char temp2 = (*dest++ = temp1) // Copy temp1 to *dest, increment dest, and also copy value to temp2
  23. if (!temp2) return ret; // return if the value that was copied is a null byte
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement