By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,189 Members | 902 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,189 IT Pros & Developers. It's quick & easy.

Hello: Question about using tolower()

P: 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
Share this Question
Share on Google+
5 Replies


sicarie
Expert Mod 2.5K+
P: 4,677
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

P: 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
Expert 2.5K+
P: 3,652
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

P: 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

P: 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

Post your reply

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