    01: #include <iostream>
    02:
    03: using namespace std;
    04:
    05: /**
    06:    Appends as much as possible from a string to another string
    07:    @param s the string to which t is appended
    08:    @param s_maxlength the maximum length of s (not counting '\0')
    09:    @param t the string to append
    10: */
    11: void append(char s[], int s_maxlength, const char t[])
    12: {
    13:    int i = strlen(s);
    14:    int j = 0;
    15:    /* append t to s */
    16:    while (t[j] != '\0' and i < s_maxlength)
    17:    {
    18:       s[i] = t[j];
    19:       i++;
    20:       j++;
    21:    }
    22:    /* add zero terminator */
    23:    s[i] = '\0';
    24: }
    25:
    26: int main()
    27: {
    28:    const int GREETING_MAXLENGTH = 10;
    29:    char greeting[GREETING_MAXLENGTH + 1] = "Hello";
    30:    char t[] = ", World!";
    31:    append(greeting, GREETING_MAXLENGTH, t);
    32:    cout << greeting << "\n";
    33:    return 0;
    34: }
    35: