Thread: how do you use tolower()

  1. #1
    Registered User
    Join Date
    Sep 2005

    how do you use tolower()

    hello, I have a character array with a string in it and it has an uppercase letter, I'm trying to convert it to all lowercase letters, I heard that the function tolower can be used, i put the ctype.h header in but i can't get it to turn my capital letter to a lower case letter

    could anyone tell me what am I doing wrong, here is my code, it's pretty simple

    thank you

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    main() {
    char word[] = "Hello"; 
    int n = 0;
    printf(" %s \n ", word);
    while ( n <= 3 ){
          tolower( word[n]);
          n++; }
          printf(" %s \n ", word);

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    tolower() can't store the modified character so you have to call it like:
    word[n] = tolower( word[n] );
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User TactX's Avatar
    Join Date
    Oct 2005
    tolower() returns the converted letter. You have to write the returned value into your array word.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    For tolower() you should include <ctype.h>.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tolower and locale
    By MK27 in forum C Programming
    Replies: 16
    Last Post: 02-03-2009, 09:05 PM
  2. tolower error
    By Livijn in forum C++ Programming
    Replies: 37
    Last Post: 05-31-2007, 11:37 PM
  3. tolower function problem
    By Jack-Bauer in forum C++ Programming
    Replies: 6
    Last Post: 05-18-2006, 11:17 PM
  4. Newbie - tolower()
    By 98dodgeneondohc in forum C Programming
    Replies: 7
    Last Post: 04-14-2005, 07:55 AM
  5. Tolower
    By webren in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2005, 08:17 PM