473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Tolower function

2
Hello everyone its Angela again. Can anyone help me please?
i want to convert uppercase characters to lower case using the <stdlib.h>
and the function tolower. for example i want to display "HELLO" to lower.

my code is:

#include<iostream.h>
#include<stdlib.h>

void main() {

cout<<tolower("HELLO");


}

i get the error : implicit declaration of function int to lower(.....)


what am i doing wrong?
Jan 10 '07 #1
3 3227
Banfa
9,065 Expert Mod 8TB
Not including ctype.h
Jan 10 '07 #2
horace1
1,510 Expert 1GB
As indicated by Banfa you need to include the appropriate header but also the function tolower() takes a single character (Iint) as a parameter and returns the corresponding lowercase letter (int), i.e.
Expand|Select|Wrap|Line Numbers
  1.      int tolower(int c);
  2.  
so you have to have a loop changing each character in turn, e.g.
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<cctype>        // for tolower()
  3. using namespace std;
  4.  
  5. int main() {
  6.     char upper[]="HELLO", lower[10]={0};
  7.     int i;
  8.     for(i=0; i<strlen(upper); i++)
  9.        lower[i] = tolower(upper[i]);  // convert each character
  10.     cout<< lower << endl;
  11.     cin.get();
  12. }
  13.  
if you are using a string you can use the transform() function
http://www.josuttis.com/libbook/string/iter1.cpp.html

e.g.
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<cctype>        // for tolower()
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7.     string s("HELLO");
  8.     transform(s.begin(), s.end(), s.begin(), (int(*)(int))std::tolower);
  9.     cout<< s << endl;
  10.     cin.get();
  11. }
  12.  
Jan 11 '07 #3
Ganon11
3,652 Expert 2GB
As indicated by Banfa you need to include the appropriate header but also the function tolower() takes a single character (Iint) as a parameter and returns the corresponding lowercase letter (int), i.e.
Expand|Select|Wrap|Line Numbers
  1.      int tolower(int c);
  2.  
so you have to have a loop changing each character in turn, e.g.
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<cctype>        // for tolower()
  3. using namespace std;
  4.  
  5. int main() {
  6.     char upper[]="HELLO", lower[10]={0};
  7.     int i;
  8.     for(i=0; i<strlen(upper); i++)
  9.        lower[i] = tolower(upper[i]);  // convert each character
  10.     cout<< lower << endl;
  11.     cin.get();
  12. }
  13.  
I am fairly certain that you will have to use a static_cast statement when assigning values to lower. Since tolower(int) returns an integer, it must be cast to a character value. The statement

Expand|Select|Wrap|Line Numbers
  1. lower[i] = tolower(upper[i]);
should be changed to

Expand|Select|Wrap|Line Numbers
  1. lower[i] = static_cast<char>(tolower(upper[i]));
Jan 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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
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
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;
2
by: Daniel Aarno | last post by:
As far as I can tell the locale header should provide a tolower function however the following failes for me under gcc 3.4. transform(begin, end, begin2, std::tolower); with an error that the...
4
by: Eric Lilja | last post by:
Hello, consider this program: #include <iostream> #include <algorithm> #include <string> #include <cctype> int main() { std::string s = "HEJ";
4
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...
8
by: Roman Mashak | last post by:
Hello, what's the point to declare argument to these functions of 'int' type, not char? With best regards, Roman Mashak. E-mail: mrv@tusur.ru
10
by: Gunvant Patil | last post by:
*p++ = tolower(*p)); is this behaviour defined in standards? Suppose p points to "ABCD" On BSD after executing above statement *(p-1) is "a" means tolower is passed with non incremented...
6
by: tgnelson85 | last post by:
Hello, I've managed to get my c++ code calling my c code, and i can call a function that prints something to the screen etc. However, i am trying to call the following C function: char*...
13
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.