... s1); // concatenate s1 to s3
25     cout << "\n\nAfter strcat(s3, s1):\ns1 = " << s1
26        << "\ns3 = " << s3 << endl;
27  }

s1 = Happy
s2 = New Year

After strcat(s1, s2):
s1 = Happy New Year
s2 = New Year

After strncat(s3, s1, 6):
s1 = Happy New Year
s3 = Happy

After strcat(s3, s1):
s1 = Happy New Year
s3 = Happy Happy New Year

Comparing Strings with strcmp and strncmp

Figure 22.24 compares three strings using strcmp (lines 14–16) and strncmp (lines 19–21). Function strcmp compares its first string argument with its second string argument character by character. The function returns zero if the strings are equal, a negative value if the first string is less than the second string and a positive value if the first string is greater than the second ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.