/////////////////////////////////////////////////////////////// // exmp2a.cpp - C string operations // // // // Jim Fawcett, ELE591\791, Su'99 // // // // build: cl /GX exmp2a.cpp // /////////////////////////////////////////////////////////////// #include #include using namespace std; //----< function reverses chars in string >-------------------- char* reverse(char *s) { int i, len = strlen(s); char *temp = new char[len+1]; if(!temp) throw "\n memory allocation failure\n\n"; for(i=0; i------------------------------------------------- void main() { cout << "\n Demonstrating C Strings " << "\n =========================\n\n"; char *str1 = "this is a C style string"; cout << "\n String before reversing: " << str1; char *str2 = reverse(str1); cout << "\n String after reversing: " << str2; cout << "\n\n string comparison:\n"; if(strcmp(str1,str2) == 0) cout << "\n \"" << str1 << "\"\n\t equals \n\t\t\"" << str2 << "\"\n\n"; else if(strcmp(str1,str2) > 0) cout << "\n \"" << str1 << "\"\n\t is greater than \n\t\t\"" << str2 << "\"\n\n"; else cout << "\n \"" << str1 << "\"\n\t is less than \n\t\t\"" << str2 << "\"\n\n"; delete str2; }