tolower function in C

A

Ahsan

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,
 
R

Rob Williscroft

Ahsan wrote in 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.
 
D

David Harmon

On 8 May 2004 07:15:17 -0700 in comp.lang.c++, (e-mail address removed)
(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);
 
J

John Harrison

David Harmon said:
On 8 May 2004 07:15:17 -0700 in comp.lang.c++, (e-mail address removed)
(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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,187
Latest member
RosaDemko

Latest Threads

Top