convert a string to all-lowercase string

  • Thread starter federico_bertola
  • Start date
K

Keith Thompson

santosh said:
Keith Thompson wrote: [...]
Others have pointed out the redundancy of the isalpha() and isupper()
calls.

I knew that isupper() is redundant, but I retained it just to keep the
logic of the routine straightforward, (a tolower() on it's own would
need additional explanations to the OP).

IMHO it's an explanation that's well worth making. If you're going to
use tolower(), you should understand how it works; part of that is
understanding how it behaves with arguments for which isupper() is
false. (It's certainly easier to understand than the need (sometimes)
to cast the argument to unsigned char.)
 
F

federico_bertola

Thx guys, really!
I've no idea what to do whithout you!
I have just made it!
Thx again my friend :)))
 
M

Mark L Pappin

Jack Klein said:
Yes, I probably did. Thanks.

With my pedantic-hat on, no you probably didn't, since (IIRC)
identifiers beginning with 'str' followed by a lowercase letter are
reserved for the Implementor ...

mlp
 
A

av

#include <ctype.h>

char *(string_to_lower char *s)
{
char *ret = s;

if (s)
{
while (*s)
{
if (*s > 0)
{
*s = tolower(*s);
}
++s;
}
}
return ret;
}

why not this?

char* to_lower(char* s)
{char *ret = s;
if(s) for( ;*s; ++s)
*s = tolower((unsigned char)*s);
return ret;
}
 

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,774
Messages
2,569,599
Members
45,170
Latest member
Andrew1609
Top