06 August 2010

strcat using arrays

#include <stdio.h>

void strcat2(char[], const char[], const char[]);

int main(void)
{
char a[] = "abc";
char b[] = "efg";
char ret[10];

strcat2(ret, a, b);

printf("%s\n", ret);

return 0;
}

void strcat2(char ret[], const char a[], const char b[])
{
int i=0, j=0;
while ( (ret[i++]=a[i]) != '\0');
i--;
while ( (ret[i++]=b[j++]) != '\0');
ret[i] = '\0';
}

Post a Comment