#include using namespace std; #include #define MAX 11 const char* truncate(char* s, int n); int main( ) { char str[] = "This is OOP244"; cout << "Before: " << str << endl; strcpy(truncate(str, MAX), str); /* ERROR */ cout << "After: " << truncate(str, MAX) << endl; cout << "str array's contents are now:" << str << endl; return 0; } // truncate contents of s[] at s[n-1] // const char* truncate(char* s, int n) { // prevents functions from returning a value // Better a compile error than a program problem later on ... if (strlen(s) > n) s[n] = '\0'; return s; }