Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

c concatenate and allocate string

// null protected
char* strconcat(char *str1, const char *str2)
{
	char *str = NULL;
    size_t len1 = 0;
    size_t len2 = 0;

	if (str1)
    	len1 = strlen(str1);
    if (str2)
    	len2 = strlen(str2);
    if (!(str = calloc(sizeof(char), (len1 + len2 + 1))))
        return NULL;
    if (str1)
        memcpy(str, str1, len1);
    if (str2)
        memcpy(str + len1, str2, len2);
    return (str);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #concatenate #allocate #string
ADD COMMENT
Topic
Name
3+4 =