PDA

View Full Version : C++



Damnatory
09-04-2003, 05:40 PM
Anyone here know how to write a function in C++ that will cause the characters that a user inputs to be capitalized on the first letter but set all the other characters to lower case? :huh:

Example:
User input = jErRy
After function = Jerry

Would really appreciate some help.

btw... Man, it's great to be back to the original forum.

4play
09-04-2003, 05:47 PM
erm this might be better placed in a programming forum but my guess would be use the old upcase command but no idea how to do it only on the first letter.

www.cprogramming.com (http://www.cprogramming.com) is an excellent forum for c and ++ help.

Amarjit
09-04-2003, 06:40 PM
I don't think they're is a function in the global header files to achieve this but here goes:


#include <iostream.h>
#include <string.h>
using namespace std;

void fUpper()
{

if ( ::pszInput == "jErRy" )
{
::pszInput = "Jerry"
cout << "Input capitalised." << endl;
}

}

int main()
{

string pszInput;
cout << "Please enter a word." << endl;
cin >> pszInput;
cout << "Thanks, it will now be capitalised." << endl;
     fUpper();

return 0;

}

Damnatory
09-04-2003, 07:45 PM
Thanks amarjit, you've gotten me off to a start, I suppose I'll post it later to show my progress.



Sorry it's been to long away from the original forum, I forgot there was a programming forum here... :lol:
Stupid temp forum was horrible.

VB
09-04-2003, 08:41 PM
Shouldn&#39;t you be doing your homework yourself <_< :lol:

shn
09-05-2003, 12:37 AM
Originally posted by Paul@4 September 2003 - 14:41
Shouldn&#39;t you be doing your homework yourself <_< :lol:
Lol :lol:

Ill be sure to come here next time I have trouble with my advanced vb.net class.

4play
09-05-2003, 12:42 AM
a linux user forced to learn vb :lol:

Damnatory
09-10-2003, 06:08 AM
Oh yeah I forgot I was gonna post the function when I was done with it.
I used the idea that ASCII decimal values are 32 points away from each other.

Here is what I came up with. It works like a champ.


void ToTitleCase( char ptr[] )
{
if ( *ptr >=&#39;a&#39; && *ptr <=&#39;z&#39; ) {
*ptr -= 32; //changes from lower case to upper
}//endif
ptr++;
while ( *ptr ) {
&nbsp; if ( *ptr >=&#39;A&#39; && *ptr <=&#39;Z&#39; ) {
&nbsp; *ptr += 32; //changes from upper case to lower
&nbsp; }//endif
&nbsp; ptr++;
&nbsp; }//endwh
}//endfn ToTitleCase

Believe it or not Amarjit, you actually helped with this more than it seems. You got me looking for the upper and lower headers, then my refence book said something about ASCII, so I took a program that my C++ professor wrote and brought it home. It&#39;s got all the ASCII char values for binary/hex/oct/dec/and chr. It&#39;s really quite cool.