tolower() and toupper()

R

Roman Mashak

Hello,

what's the point to declare argument to these functions of 'int' type, not
char?

With best regards, Roman Mashak. E-mail: (e-mail address removed)
 
G

Guest

Roman said:
Hello,
[ tolower() and toupper() ]
what's the point to declare argument to these functions of 'int' type, not
char?

This allows you to pass EOF as an argument (which will be returned as
EOF), and in C90 (the most widely supported version C standard), it
also allows you to call these functions without including <ctype.h>.
 
R

Roman Mashak

Hello, Harald!
You wrote on 1 Nov 2006 02:44:50 -0800:

??>> what's the point to declare argument to these functions of 'int' type,
??>> not char?
HvD> This allows you to pass EOF as an argument (which will be returned as
HvD> EOF), and in C90 (the most widely supported version C standard), it
HvD> also allows you to call these functions without including <ctype.h>.
What's the practical necessity to pass EOF?

With best regards, Roman Mashak. E-mail: (e-mail address removed)
 
J

Jordan Abel

2006-11-02 said:
Hello, Harald!
You wrote on 1 Nov 2006 02:44:50 -0800:

??>> what's the point to declare argument to these functions of 'int' type,
??>> not char?
HvD> This allows you to pass EOF as an argument (which will be returned as
HvD> EOF), and in C90 (the most widely supported version C standard), it
HvD> also allows you to call these functions without including <ctype.h>.
What's the practical necessity to pass EOF?

while((c = tolower(getchar()))!=EOF) {
...;
}

That's really the weakest reason though, of the ones he gives.
 
D

Dik T. Winter

> Hello,
>
> what's the point to declare argument to these functions of 'int' type, not
> char?

That is to make the following work:
int c1, c2;
while((c1 = getchar()) != EOF) {
c2 = tolower(c1);
}
 
C

CBFalconer

Dik T. Winter said:
That is to make the following work:
int c1, c2;
while((c1 = getchar()) != EOF) {
c2 = tolower(c1);
}

Which, assuming you need both the values of c1 and c2 preserved, is
more simply written as:

while (EOF != (c2 = tolower(c1 = getchar))) continue;

since the tolower call will preserve the value EOF.
 
S

Simon Biber

CBFalconer said:
Which, assuming you need both the values of c1 and c2 preserved, is
more simply written as:

while (EOF != (c2 = tolower(c1 = getchar))) continue;

since the tolower call will preserve the value EOF.

I think you meant to call getchar, rather than trying to assign a
function pointer to c1. A set of parentheses is missing.
 
R

Richard Heathfield

Simon Biber said:
I think you meant to call getchar, rather than trying to assign a
function pointer to c1. A set of parentheses is missing.

[SFX: rummage rummage]

Aha! ( )
 
C

CBFalconer

Simon said:
I think you meant to call getchar, rather than trying to assign a
function pointer to c1. A set of parentheses is missing.

Thanks for catching that. Should be:
while (EOF != (c2 = tolower(c1 = getchar()))) continue;
 

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

Similar Threads

re-definition of standard types 9
buffer overflow 20
get random number in range [10..50] 14
type casting 9
how to define the array of strings 7
missing initializer 4
type casting 9
padding mechanism in structures 10

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top