By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,327 Members | 1,777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,327 IT Pros & Developers. It's quick & easy.

tolower function in C

P: n/a
Hi All,
I am having prolems with converting upper case characters to lower
case in Unix's C. I saw the man pages and "tolower" function does it.
But in my case its not working.
My code is as follows:
================================================== ==========
gets ( input );
sscanf(input, "%s", Cmd);

for( p = 0; p < strlen( Cmd ); p++ )/* Changing all input to lower
characters */
{
printf("hello in loop");
if( isupper( Cmd[p] ) )
{
_tolower( Cmd[p] );
printf("%c", Cmd[p]);
}
}
================================================== ===========

Anxiously Waiting for reply,
Regards,
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Ahsan wrote in news:56**************************@posting.google.c om in
comp.lang.c++:
Hi All,
I am having prolems with converting upper case characters to lower
case in Unix's C. I saw the man pages and "tolower" function does it.
But in my case its not working.
My code is as follows:
================================================== ==========
gets ( input );
Don't use this, if you must use fgets instead.
sscanf(input, "%s", Cmd);

for( p = 0; p < strlen( Cmd ); p++ )/* Changing all input to lower
characters */
{
printf("hello in loop");
if( isupper( Cmd[p] ) )
{
_tolower( Cmd[p] );
Your man page is 'tolower' yet you use '_tolower'
printf("%c", Cmd[p]);
}
}
================================================== ===========

Anxiously Waiting for reply,


This newsgroup is comp.lang.c++ your code appears to be C not C++.
You should use comp.lang.c for discussing "Standard C" or
comp.unix.programmer for discussing "Unix programming".

AFAICT, non-standard _tolower aside, the above could be
part of a Standard C programme.

HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2

P: n/a
On 8 May 2004 07:15:17 -0700 in comp.lang.c++, al******@hotmail.com
(Ahsan) wrote,
for( p = 0; p < strlen( Cmd ); p++ )/* Changing all input to lower
characters */
{
printf("hello in loop");
if( isupper( Cmd[p] ) )
{
_tolower( Cmd[p] );
printf("%c", Cmd[p]);
}
}


std::transform(Cmd, Cmd+strlen(Cmd), Cmd, std::tolower);

Jul 22 '05 #3

P: n/a

"David Harmon" <so****@netcom.com> wrote in message
news:41****************@news.west.earthlink.net...
On 8 May 2004 07:15:17 -0700 in comp.lang.c++, al******@hotmail.com
(Ahsan) wrote,
for( p = 0; p < strlen( Cmd ); p++ )/* Changing all input to lower
characters */
{
printf("hello in loop");
if( isupper( Cmd[p] ) )
{
_tolower( Cmd[p] );
printf("%c", Cmd[p]);
}
}


std::transform(Cmd, Cmd+strlen(Cmd), Cmd, std::tolower);


It's nice, but it's not guaranteed to work if char is a signed type.

char tedious_but_necessary(char ch)
{
return std::tolower((unsigned char)ch))
}

std::transform(Cmd, Cmd+strlen(Cmd), Cmd, tedious_but_necessary);

john
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.