#include #include main() { char a[] = "C++ programming", b[50], c[50], d[50]; int i; cout << "a contains " << strlen(a) << " characters\n"; // 15 characters strcpy(b, "Welcome to this program!"); // b is initialized strncpy(c, b, 11); // "Welcome to " is stored in c // The following statement is necessary because // strncpy does not automatically append '\0' at the end of the string c[11] = '\0'; strcpy(d, c); // "Welcome to " is stored in d strncat(c, a, 3); // "Welcome to C++" is stored in c strcat(d, a); // "Welcome to C++ programming" is stored in d // b: "Welcome to this program!" // c: "Welcome to C++" // d: "Welcome to C++ programming" cout << "b: " << b << "\nc: " << c << "\nd: " << d << endl; // Here we can see that b > d if (strcmp(b, d) > 0) cout << "b > d\n"; else if (strcmp(b, d) == 0) cout << "b = d\n"; else cout << "b < d\n"; for (i = 0; !strncmp(b, d, i); i++) ; // the loop body is empty // The above for loop is exited when strncmp(b, d, i) == 0 cout << "b and d differ at character " << i << "." << endl; return 0; }