How to use tolower command for a string??

This is a discussion on How to use tolower command for a string?? within the C++ Programming forums, part of the General Programming Boards category; How to use tolower command for a string?? for example: printf("Please inout the word for convert:"); scanf("%s", result ); result ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    3

    Unhappy How to use tolower command for a string??

    How to use tolower command for a string??

    for example:

    printf("Please inout the word for convert:");


    scanf("%s", result);

    result[6]=tolower( result[6]);


    ptr = strcmp(result, word );


    how come the program can work, but it doesn't convert?

    the variable result (a string), iz the 1 which i wan to convert.
    the variable word (a string) is the 1 which i wan to compare with. So no matter the content of result iz a big letter, ir a small letter, the compare result will still be the same.

    pls help mi..~~
    thanx

  2. #2
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    You will probley need to convert each element seperatly in a character array. But I wounder how it would handle a string type.

  3. #3
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Code:
    cout << "\nEnter string: ";
    	cin >> userInput;
    
    		for (int i = 0; i < strlen(userInput); i++)
    	{
    		userInput[i] = tolower(userInput[i]);
    	}

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    string is an stl container as sure as list and vector are. As such they have iterartors and support algorithms. You want std::transform() from algorithm going from begin() to end() passing tolower.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    3

    Wink

    thanx guys
    especially RoD,

    it really help mi alot, i'v finish my project


  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You could also read the FAQ
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    3

    Cool Prevent from an error

    example below:


    printf("How many chances you wish to have?? (MAXIMUM is 20)\n");
    scanf("%d", &chance);


    If the user ACCIDENTALLY hit a alphabet on the keyboard, the program will have error, as the input must be an integer...

    How can i prevent the error even the user click in an alphabet, and also it need to be a %d at the same time?

    iz there a way to prompt the user to enter again as the input muz be an integer???

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Use fgets() to read a string, check if it only contain digits (no letters and special characters) then use atoi() to convert it to an integer.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Are you writing C or C++ ? Make up your mind, and post on the correct board.

    The FAQ covers reading numbers in C and C++. I suggest you read it.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 07:02 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21