2
0

strcpy.c 626 B

1234567891011121314151617181920212223242526272829
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "test_helpers.h"
  4. int main(void) {
  5. char dst[20];
  6. strcpy(dst, "strcpy works!");
  7. puts(dst);
  8. strncpy(dst, "strncpy works!", 20);
  9. puts(dst);
  10. // Make sure no NUL is placed
  11. memset(dst, 'a', 20);
  12. dst[19] = 0;
  13. strncpy(dst, "strncpy should work here too", 10);
  14. puts(dst);
  15. // The string should be properly terminated regardless
  16. char ndst[28];
  17. size_t r = strlcpy(ndst, "strlcpy works!", 28);
  18. puts(ndst);
  19. printf("copied %lu\n", r);
  20. r = strlcat(ndst, " and strlcat!", 28);
  21. puts(ndst);
  22. printf("copied %lu\n", r);
  23. }