home *** CD-ROM | disk | FTP | other *** search
- /*
- C++ program that demonstrates manupilating the
- characters in a string
- */
-
- #include <iostream.h>
- #include <string.h>
-
- const unsigned STR_SIZE = 40;
- const int TRUE = 1;
- const int FALSE = 0;
-
- main()
- {
- char str1[STR_SIZE+1];
- char str2[STR_SIZE+1];
- int isLowerCase;
- int isUpperCase;
- int isSymmetrical;
-
-
- cout << "Enter a string : ";
- cin.getline(str1, STR_SIZE);
- cout << "Input: " << str1 << "\n";
- // copy str1 to str2
- strcpy(str2, str1);
- // convert to lowercase
- strlwr(str2);
- isLowerCase = (strcmp(str1, str2) == 0) ? TRUE : FALSE;
- cout << "Lowercase: " << str2 << "\n";
- // convert to uppercase
- strupr(str2);
- isUpperCase = (strcmp(str1, str2) == 0) ? TRUE : FALSE;
- cout << "Uppercase: " << str2 << "\n";
- // copy str1 to str2
- strcpy(str2, str1);
- // reverse characters
- strrev(str2);
- isSymmetrical = (strcmp(str1, str2) == 0) ? TRUE : FALSE;
- cout << "Reversed: " << str2 << "\n";
- if (isLowerCase)
- cout << "Your input has no uppercase letters\n";
- if (isUpperCase)
- cout << "Your input has no lowercase letters\n";
- if (isSymmetrical)
- cout << "Your input has symmetrical characters\n";
- return 0;
- }
-