Advertisement
KvArt

Strcat funkcija

Jul 12th, 2022
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. //• strcat() : string concatenate – nadovezuje string na kraj drugog stringa
  2.  
  3. //strcat() prva varijanta
  4.  
  5. char *strcat(char *dst, const char *src) {
  6. int i, j;
  7. for(i=0; dst[i] != ‘\0; i++);
  8. for(j=0 ; src[j] != ‘\0; i++, j++)
  9. dst[i] = src[j];
  10. dst[i] = ‘\0;
  11. return dst;
  12. }
  13.  
  14. //strcat() druga varijanta
  15.  
  16. char *strcat(char *dst, const char *src) {
  17. char *d = dst;
  18. while( *d != ‘\0) d++;
  19. while( *src != ‘\0)
  20. *d++ = *src++;
  21. *d = ‘\0;
  22. return dst;
  23. }
  24.  
  25. //strcat() treća varijanta
  26.  
  27. char *strcat(char *dst, const char *src) {
  28. char *d = dst;
  29. while( *d != ‘\0) d++;
  30. while( *d++ = *src++ );
  31. return dst;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement