473,498 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

tolower() and toupper()

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
8 2399
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
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
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
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
"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
31854
by: qazmlp | last post by:
I was using the following code to convert the string to lowercase. string foo = "Some Mixed Case Text"; transform(foo.begin(), foo.end(), foo.begin(), tolower); I thought the above code is...
13
5994
by: David Rubin | last post by:
I get an error when I compile the following code: #include <algorithm> #include <cctype> #include <iostream> #include <string> using namespace std; string&
11
3330
by: TheDD | last post by:
Hello, i don't manage to use the tolower() function: #include <algorithm> #include <iostream> #include <locale> #include <string> using std::cout;
9
2091
by: asbisht | last post by:
Greetings to everyone. #include<iostream> main( void ) { unsigned char value = 'A'; std::cout << tolower(value); return 0; }
4
3234
by: Eric Lilja | last post by:
Hello, consider this program: #include <iostream> #include <algorithm> #include <string> #include <cctype> int main() { std::string s = "HEJ";
0
1510
by: Shrinivas Reddy | last post by:
Hi, I am using the ToUpper() function in an FXCop rule which checks whether a boolean variable has "is" or "has" as the prefix. The ToUpper() function does not work. When I put the expression...
4
11014
by: Kelvin Moss | last post by:
HI all, I want to know if tolower can handle unicode characters (codepoints) correctly? Is it specified by the Standard? If yes, then a reference to the Standard would be appreciated. Or, is it...
4
493
by: sandy | last post by:
I am trying to upper case a string, so I have this method: string FileSystem::toupper(string S) { for (int i=0; i<S.length(); ++i) { S=toupper(S); } return S;
13
2971
by: Soumen | last post by:
I wanted convert a mixed case string to a lower case one. And I tried following code: std::transform(mixedCaseString.begin(), mixedCaseString::end(), mixedCaseString.begin(),...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5464
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3095
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.