Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with lowercase function 1

Status
Not open for further replies.

linuxjr

Programmer
Jun 2, 2001
135
US
std::string lowercase (const std::string& s)
// Converts all upper-case alphabetic characters in s to the
// corresponding lowercase characters.
{
return s;
}


I'm reading a data structures book teaching myself and I'm lost at how to go about this. I know we can take the value of s and store it then return the lowercase value but how can you do it in unix and the book goes don't use the char manipulation functions such as strcpy or to copy the characters in an array, convert then copy back to the
string. So I'm lost on this. Anyone write one for this or know of a site that has an example of this where I could study and try to get it to working. Any tips or suggestions be appreciated. Have a nice day.

 
std::string lowercase (const std::string& s)
{
std::string str(s);
std::string::iterator it;
while(it != str.end())
{
if((*it <= 'Z')&&(*it >= 'A'))
{
*it -= ('A' - 'a');
}
it++;
}
return str;
}
Ion Filipski
1c.bmp


filipski@excite.com
 
Thanks for the quick response. When I tested with my program I'm getting

0[main] test 476115 open_stackdumpfile: Dumping stack trace to Test.EXE stackdump

Segmentation fault (core dump)

I'm using the latest cygwin Compiler on Windows 98 and have a unix shell account to test.
 
I got it working now I had to add

it = str.begin();

before the while loop. Thanks and have a nice day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top