2015年9月2日 星期三

[C] Concatenate two strings together into a buffer

c.h
/*
 *  * Concatenate two strings together into a buffer
 *  * @param       s1      first string
 *  * @param       s2      second string
 *  * @param       buf     buffer large enough to hold both strings
 *  * @return      buf
 *  */
static inline char * strcat_k(const char *s1, const char *s2, char *buf)
{
        strcpy(buf, s1);
        strcat(buf, s2);
        return buf;
}

c.c
#include<stdio.h>
#include <string.h>
#include "c.h"
int main()
{
    char buf[128];   

    strcat_k("happy_","GOOD",buf);
    printf("%s \n",buf);
    return 0;

}

Result:
happy_GOOD


Reference:

0 意見:

張貼留言