#include <stdio.h>
#include <stdlib.h>
size_t str_copy2buf(size_t n, char buf[n], const char str[])
{
size_t i;
for (i = 0; i < n; i++) {
if ((buf[i] = str[i]) == '\0')
break;
}
return i;
}
size_t str_append2buf(size_t n, char buf[n], const char str[])
{
size_t i, j;
for (i = 0; i < n; i++) {
if (buf[i] == '\0')
break;
}
for (j = 0; i < n; i++) {
if ((buf[i] = str[j]) == '\0')
break;
j++;
}
return i;
}
int main(int argc, char *argv[argc+1])
{
char buf[15];
size_t index;
index = str_copy2buf(sizeof(buf), buf, argv[1]);
if (index == sizeof(buf)) {
fprintf(stderr, "error: copy failed!\n");
return EXIT_FAILURE;
}
index = str_append2buf(sizeof(buf), buf, argv[2]);
if (index == sizeof(buf)) {
fprintf(stderr, "error: append failed!\n");
return EXIT_FAILURE;
}
printf("%s\n", buf);
return EXIT_SUCCESS;
}