473,387 Members | 1,579 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,387 software developers and data experts.

Hello: Question about using tolower()

3
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 2215
sicarie
4,677 Expert Mod 4TB
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
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 Expert 2GB
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
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
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
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&
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";
11
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...
0
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...
10
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...
1
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...
4
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.