fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. unsigned int ft_strlen (char *str)
  5. {
  6. unsigned int i;
  7.  
  8. i = 0;
  9. while (str[i] != '\0')
  10. i++;
  11. return i;
  12. }
  13.  
  14. size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
  15. {
  16. unsigned int j;
  17. unsigned int i;
  18. unsigned int len_dst;
  19. unsigned int len_src;
  20.  
  21. j = ft_strlen(dst);
  22. i = 0;
  23. len_dst = ft_strlen(dst);
  24. len_src = ft_strlen(src);
  25. if (dstsize < 1)
  26. return (len_src + dstsize);
  27. while (src[i] && j < dstsize - 1)
  28. {
  29. dst[j] = src[i];
  30. j++;
  31. i++;
  32. }
  33. dst[j] = '\0';
  34. if (dstsize < len_dst)
  35. return (len_src + dstsize);
  36. else
  37. return (len_dst + len_src);
  38. }
  39.  
  40.  
  41. int main(void) {
  42. char foo_src[7] = "Hello ";
  43. char foo_dest[9] = "World! ";
  44.  
  45. printf("%d\n", ft_strlcat(foo_dest, foo_src, 0));
  46. ft_strlcat(foo_dest, foo_src, 9);
  47. //strlcat(foo_dest, foo_src, 10);
  48. printf("%s\n", foo_dest);
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
6
World! H