home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tybc4
/
advfun2.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-31
|
909b
|
44 lines
/*
C++ program that declares functions with string parameters
*/
#include <iostream.h>
const unsigned MAX = 40;
char* upperCase(char* str)
{
int ascii_shift = 'A' - 'a';
char* p = str;
// loop to convert each character to uppercase
while ( *p != '\0') {
if ((*p >= 'a' && *p <= 'z'))
*p += ascii_shift;
p++;
}
return str;
}
int strlen(char* str)
{
char *p = str;
while (*p++ != '\0');
return --p - str;
}
main()
{
char aString[MAX+1];
cout << "Enter a string: ";
cin.getline(aString, MAX);
cout << "Your string has " << strlen(aString)
<< " characters\n";
// concatenate bigStr to aString
upperCase(aString);
cout << "The uppercase version of your input is: "
<< aString;
return 0;
}