Re: convert a string to all-lowercase string



Keith Thompson wrote:
"santosh" <santosh.k83@xxxxxxxxx> writes:
federico_bert...@xxxxxxxxxx wrote:
err... hehe,
I understand what do you mean but if you can post a sample code please!
(I'm a newbye)
Thx for the help :)

#include <stdio.h>
#include <ctype.h>

int main(void) {
int c;

while((c = getchar()) != EOF) {
if(isalpha((unsigned char) c)) {
if(isupper((unsigned char) c))
c = tolower((unsigned char) c);
}
putchar(c);
}
return 0;
}

Note that this doesn't address the original question. The OP wanted
to convert a string to lower case; you're converting stdin to lower
case and writing it to stdout. (Perhaps this was intentional, to
avoid doing the OP's homework.)

Indeed, though in hindsight my post has, (justifiably), recieved so
many replies, I wonder if the OP is confused, (he admitted to being a
newbie).

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).

.



Relevant Pages