473,795 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hello: Question about using tolower()

3 New Member
Hello, this is my first post, so hopefully I am posting this in the right place.

Hopefully someone will be able to help me out with my problem here it is:


I need to make a program that ask a user to input a word. However when they input that word I need to convert the word to all lowercase letters so it can do a serach. This is my problem:

Every time I try to use tolower it gives me an error

"Cannot convert parameter 1 from 'char[11]' to 'int'

I notice that I can use this when the person only has to input one character, but when it's an entire word, tolower doesn't work.


Here is a sample of what I am trying to do (I switched some of the text around since it says don't post your source code). I tried to only put what I need, but if more code is needed, let me know I will glady add more if I need too.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <ctype.h>
  5. using namespace std;
  6.  
  7. int main ()
  8. {
  9.  
  10. char word[11];
  11.  
  12. cout << "Please, enter the the word you need to search for";
  13.     cin.getline(word, 11);
  14.  
  15.  
  16.     word = tolower(word);
  17.  
  18.     cout << endl;
  19. }
  20.  
Any help is appreciated, thank you :)
Feb 21 '07 #1
5 2232
sicarie
4,677 Recognized Expert Moderator Specialist
Hello, this is my first post, so hopefully I am posting this in the right place.

Hopefully someone will be able to help me out with my problem here it is:


I need to make a program that ask a user to input a word. However when they input that word I need to convert the word to all lowercase letters so it can do a serach. This is my problem:

Every time I try to use tolower it gives me an error

"Cannot convert parameter 1 from 'char[11]' to 'int'

I notice that I can use this when the person only has to input one character, but when it's an entire word, tolower doesn't work.


Here is a sample of what I am trying to do (I switched some of the text around since it says don't post your source code). I tried to only put what I need, but if more code is needed, let me know I will glady add more if I need too.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <ctype.h>
  5. using namespace std;
  6.  
  7. int main ()
  8. {
  9.  
  10. char word[11];
  11.  
  12. cout << "Please, enter the the word you need to search for";
  13.     cin.getline(word, 11);
  14.  
  15.  
  16.     word = tolower(word);
  17.  
  18.     cout << endl;
  19. }
  20.  
Any help is appreciated, thank you :)
Did you try declaring word as a string?
Feb 21 '07 #2
Faray
3 New Member
Did you try declaring word as a string?
Hello, thanks for the fast reply

I tried declaring it as a string, it gives me some errors, it might be becuase I have more coding for the program.

I also tried something like

Expand|Select|Wrap|Line Numbers
  1.  
  2. string convert = word;
  3.  
  4. convert = tolower(convert) ;
  5.  
  6.  
and I get an error

"Cannot convert from string to int"

I might be doing the declaring wrong, since I haven't worked with strings much yet.

Incase you couldn't tell, I'm not the most brillant C++ user, so forgive me if I'm sounding really stupid.

Thanks agian.
Feb 22 '07 #3
Ganon11
3,652 Recognized Expert Specialist
tolower() only takes a single character argument (actually passed as an integer), so you cannot pass it a character array. You will have to loop through the array and change each character individually using tolower().

Note that tolower() actually returns an integer - you have have to cast this result to a character when changing.
Feb 22 '07 #4
Faray
3 New Member
tolower() only takes a single character argument (actually passed as an integer), so you cannot pass it a character array. You will have to loop through the array and change each character individually using tolower().

Note that tolower() actually returns an integer - you have have to cast this result to a character when changing.
Alright, I'll play around with that tomorrow. I'm not 100% sure on how to do that, but I'll try it and see if I can figure it out first before I ask again. Thanks again for your help
Feb 22 '07 #5
rajgkk
3 New Member
See a program to reverse the case
Refer MSDN before posting any thing...
U can find almost all examples and hacks there.......

Expand|Select|Wrap|Line Numbers
  1. #include <ctype.h>
  2. #include <string.h>
  3.  
  4. char msg[] = "Some of THESE letters are Capitals.";
  5. char *p;
  6.  
  7. int main( void )
  8. {
  9.    printf( "%s\n", msg );
  10.  
  11.    /* Reverse case of message. */
  12.    for( p = msg; p < msg + strlen( msg ); p++ )
  13.    {
  14.       if( islower( *p ) )
  15.          putchar( _toupper( *p ) );
  16.       else if( isupper( *p ) )
  17.          putchar( _tolower( *p ) );
  18.       else
  19.          putchar( *p );
  20.    }
  21. }
Feb 22 '07 #6

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

Similar topics

3
31871
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
6032
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&
2
1838
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
3254
by: Eric Lilja | last post by:
Hello, consider this program: #include <iostream> #include <algorithm> #include <string> #include <cctype> int main() { std::string s = "HEJ";
11
11470
by: xuatla | last post by:
Hi, I want to compare two strings regardless of the lowercase or uppercase. For example, "txt" same as "TXT", "Txt", ... I know that there's stricmp in some c++ that can perform a lowercase comparison. But when I use <cstring>, I can't find such function. Do you know any other standard c++ function(s) can do this task? Thanks,
0
291
by: Dan | last post by:
Hi all, I'd like to submit what it seems to be a bug as for the Unicode compliance of methods like Char.Is...: as stated by the latest version of Unicode, codes +03F2 and +03F9 represent Greek lunate sigma, lowercase and uppercase respectively (c and C). For these codes I get the following results: +03F2: lowercase c: Char.IsLetter() = true (OK) Char.IsUpper() = false (OK) Char.IsLower() = true (OK)
10
7932
by: Anthony Williams | last post by:
Hi gang, This one looks like a bug :o( As you may or may not know, setting session management in web.config to use cookieless sessions causes the ASP.NET runtime to munge a session ID into the URL, in the format http://yourapplicationpath/(Session.SessionID)/... which saves numerous headaches when it comes to storing state across page requests and sessions.
1
12214
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose is that I seek out terms which are in a glossary on our site, and automatically link to this definition. Its slightly complex becase certain elements have to be ignored, for exampleI dont want to add links within existing links, or for example link...
4
7655
by: damiensawyer | last post by:
Hi, I have the following situation. If a user browses to http://domain/somemiscURL.aspx without going through the front door I need to catch the request, forward them to a login page and then, on completion, send them to the original page that they requested. My 'plan' was to do the following. 1/ Catch every request and test if it's "logged in" (determined by existence of an object help in the Session
0
9672
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
10436
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
10163
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,...
0
9040
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
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
5436
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.