char MiddleCharacter( ); //Returns the "middle" character of the
//string. If the string length is even
//then the right-most character of the
//"left" half is returned.
how to find the middle character in a string
Thank you
char MiddleCharacter( ); //Returns the "middle" character of the
//string. If the string length is even
//then the right-most character of the
//"left" half is returned.
how to find the middle character in a string
Thank you
and one more thing. I'm trying to do that with Cstring
Thanks
Is Cstring a class? If it lets you get an individual character and the size, you can do this easy.
char MiddleCharacter( Cstring string ) {
return string[string.length() / 2];
}
A char array string is the same way but you have to use strlen.
char MiddleCharacter( const char *string ) {
return string[strlen( string ) / 2];
}
No biggie, right? :)
Thanks a lot, that was helpful.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.