473,804 Members | 3,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tolower function

2 New Member
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<iostre am.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 3256
Banfa
9,065 Recognized Expert Moderator Expert
Not including ctype.h
Jan 10 '07 #2
horace1
1,510 Recognized Expert Top Contributor
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 Recognized Expert Specialist
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
31872
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 portable. But, the following page has a different view on this: http://lists.debian.org/debian-gcc/2002/debian-gcc-200204/msg00092.html
13
6033
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
3365
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
1839
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 last arg is of unknown type. Any ideas on why?
4
3255
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
11040
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 implementation defined? Thanks ..
8
2416
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
1973
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 value of p On linux it is "b" means tolower is passed with incremented value of
6
2240
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* normaliseString(char *pstring) { char *ptr; for(ptr = pstring; *ptr; ptr++) {
13
3003
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(), std::ptr_fun(tolower)); Even though I's including cctype and algorithm, I's getting compiler (g ++ 3.3.6) error: no matching function for call to `ptr_fun(<unknown type>)'
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10580
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10323
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7621
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
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 we have to send another system
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2993
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.