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