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

tolower() and toupper()

P: n/a
Hello,

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

With best regards, Roman Mashak. E-mail: mr*@tusur.ru
Nov 1 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Roman Mashak wrote:
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>.

Nov 1 '06 #2

P: n/a
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?
HvDThis allows you to pass EOF as an argument (which will be returned as
HvDEOF), and in C90 (the most widely supported version C standard), it
HvDalso 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: mr*@tusur.ru
Nov 2 '06 #3

P: n/a
2006-11-02 <ei**********@relay.tomsk.ru>,
Roman Mashak wrote:
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?
HvDThis allows you to pass EOF as an argument (which will be returned as
HvDEOF), and in C90 (the most widely supported version C standard), it
HvDalso 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.
Nov 2 '06 #4

P: n/a
In article <ei**********@relay.tomsk.ru"Roman Mashak" <mr*@tusur.ruwrites:
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);
}
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 2 '06 #5

P: n/a
"Dik T. Winter" wrote:
"Roman Mashak" <mr*@tusur.ruwrites:
>>
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);
}
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.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Nov 2 '06 #6

P: n/a
CBFalconer wrote:
"Dik T. Winter" wrote:
>"Roman Mashak" <mr*@tusur.ruwrites:
>>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);
}

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.

--
Simon.
Nov 2 '06 #7

P: n/a
Simon Biber said:
CBFalconer wrote:
>>
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.
[SFX: rummage rummage]

Aha! ( )

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 2 '06 #8

P: n/a
Simon Biber wrote:
CBFalconer wrote:
>"Dik T. Winter" wrote:
>>"Roman Mashak" <mr*@tusur.ruwrites:
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);
}

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.
Thanks for catching that. Should be:
while (EOF != (c2 = tolower(c1 = getchar()))) continue;

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Nov 2 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.