Concatenate two string by length, like strncat - C String

C examples for String:String Function

Description

Concatenate two string by length, like strncat

Demo Code

#include <stdio.h>

void _strncat(char *s, char *t, int n);

int main(void)
{
    char *s, *t;//from w  w w.j a v a  2 s  . com

    s = "asdf";
    t = "12345678";

    _strncat(s, t, 4);
    printf("cat: %s\n", s);

    return 0;
}

void _strncat(char *s, char *t, int n)
{
    while (*s)
        ++s;
    while (n-- > 0 && *t)
        *s++ = *t++;
    *s = '\0';
}

Related Tutorials