Last active
March 2, 2020 12:47
-
-
Save jlagarespo/325778f8dc115a18b4d692ea7cde5e64 to your computer and use it in GitHub Desktop.
Implementation of some string utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void strcpy(const char *src, char *dst); | |
void strcat(char *src, const char *str); | |
int strlen(const char *src); | |
void strcpy(const char *src, char *dst) | |
{ | |
for (int i = 0; src[i] != '\0'; i++) | |
dst[i] = src[i]; | |
} | |
void strcat(char *src, const char *str) | |
{ | |
char *srcend = &(src[strlen(src)]); | |
for (int i = 0; str[i] != '\0'; i++) | |
srcend[i] = str[i]; | |
} | |
int strlen(const char *src) | |
{ | |
int sum = 0; | |
for (; *src != '\0'; src++) | |
sum++; | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment