Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- static const int MAXLEN = 11;
- // rather than side-effect of changing input string,
- // we use a local variable. so the returned string is changed.
- // so don't bother storing return values without copying them elsewhere.
- char *cStringtoUpper(const char *lower)
- {
- static char upper[MAXLEN+2];
- int i = 0;
- while (lower[i] != 0)
- {
- if (lower[i] >= 'a' && lower[i] <= 'z')
- upper[i++] = lower[i] - 0x20;
- else
- upper[i++] = lower[i];
- }
- // dont forget to null terminate the new string!
- upper[i] = 0;
- return upper;
- }
- int main()
- {
- int i;
- char line[MAXLEN+2];
- cout << "This program will convert strings up to " << MAXLEN <<
- " characters of length into uppercase.\n" <<
- "You may exit by inputting 'Q' (in uppercase!)\n\n";
- while (1)
- {
- cout << "Enter string: ";
- cin.get(line, MAXLEN+1);
- cin.ignore(); // strip the '\n'
- // easy check for quit. make sure it's Q alone!
- if (line[0] == 'Q' && line[1] == 0)
- break;
- cout << "In uppercase: " << cStringtoUpper(line) << endl;
- }
- cout << "\nGoodbye!\n\n";
- // signals success to executing environment.
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement