/* testpointer4.cpp CIS 150 David Klick 6/26/08 Using pointers to work with strings. */ #include using std::cin; using std::cout; void upper1(char* str); char* upper2(char* str); void cont(); int main() { char line1[] = "All the King's horses"; char line2[] = "and all the King's men"; cout << line1 << '\n'; cout << line2 << '\n'; // make the strings uppercase and display them upper1(line1); cout << line1 << '\n'; cout << upper2(line2) << '\n'; cont(); return 0; } /* void upper1(char* str); Arguments: char* str: C-style string to be converted to uppercase Returns: Nothing, but modifies string sent in to be uppercase. Converts C-style string sent in to uppercase. This function actually modifies the original string. */ void upper1(char* str) { upper2(str); } /* char* upper2(char* str); Arguments: char* str: C-style string to be converted to uppercase Returns: A pointer to the original string sent in (which will have been converted to uppercase). Converts C-style string sent in to uppercase. This function actually modifies the original string. A pointer to the string is returned to make it easy to use this function within other expressions. */ char* upper2(char* str) { char *p = str; while (*p != '\0') { if (*p >= 'a' && *p <= 'z') { *p = *p + ('A' - 'a'); } p++; } return str; } /* void cont(); Arguments: none Returns: nothing Clears input buffer and pauses waiting for user to press Enter. */ void cont() { if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press enter to continue..."; cin.get(); }