/* testchar2.cpp CIS 150 David Klick 7/3/08 This program demonstrates how to create and use simple upper/lower case functions. */ #include #include using std::cin; using std::cout; void makeLowerCase(char* str); void makeUpperCase(char* str); void cont(); int main() { char sample[] = "This is Dave's test string!"; cout << sample << '\n'; makeLowerCase(sample); cout << sample << '\n'; makeUpperCase(sample); cout << sample << '\n'; cont(); return 0; } /* void makeLowerCase(char* str); Arguments: char* str: a pointer to the string to be modified Returns: nothing This function converts a string to lowercase. Warning: It modifies the input string. */ void makeLowerCase(char* str) { while (*str != '\0') { *str = tolower(*str); str++; } } /* void makeUpperCase(char* str); Arguments: char* str: a pointer to the string to be modified Returns: nothing This function converts a string to uppercase. Warning: It modifies the input string. */ void makeUpperCase(char* str) { while (*str != '\0') { *str = toupper(*str); 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(); } /* Sample output: This is Dave's test string! this is dave's test string! THIS IS DAVE'S TEST STRING! */