CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2007
    Posts
    143

    Wink upper to lower case conversion.

    Hello guys,
    Is their any function api available to convert a character to lowercase(eg:- A to a) in C,I tried with tolower but it returns a ASCII value but i need a character as return type,help me if you know.

    thanks in advance

  2. #2
    Join Date
    Apr 2009
    Posts
    10

    Re: upper to lower case conversion.

    char cUpper = 'A';,
    char cLower;

    cLower= tolower(cUpper );

    printf("%c",cLower);

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: upper to lower case conversion.

    As luvjd79 wrote you could use C-runtime function tolower (_tolower, towlower) to convert single character to lower case.
    You can also use CharLower Windows API to convert either a single character or the whole string.
    Victor Nijegorodov

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: upper to lower case conversion.

    Quote Originally Posted by resumurof View Post
    Hello guys,
    Is their any function api available to convert a character to lowercase(eg:- A to a) in C,I tried with tolower but it returns a ASCII value but i need a character as return type,help me if you know.

    thanks in advance
    There is no difference between an ASCII value and the character it represents, unless that value is stored in more than 1 byte---in which case you can just cast it down to char.

  5. #5
    Join Date
    Jan 2007
    Posts
    143

    Wink Re: upper to lower case conversion.

    Hello Lindley,

    I need a special character Like (ä,ö,ü) to be converted to Lowerse in Linux using C/C++, I tried using tolower() but it always return -60 which is not the ASCII value of ä(228),kindly let me know if their any API available.Here is my program in.

    int main()
    {
    char *n="Ä";
    printf("%d\n",*n); //before conversion printing -60, this is wrong should return 196
    int a=tolower((int)*n);
    printf("%d\n",a); //After conversion returns -60 which is really wrong.

    }

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: upper to lower case conversion.

    Quote Originally Posted by resumurof View Post
    ... I need a special character Like (ä,ö,ü) to be converted to Lowerse in Linux using C/C++
    Well, this Forum is
    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.
    So you might want to ask it in Non-Visual C++ Forum.

    Quote Originally Posted by resumurof View Post
    int main()
    {
    char *n="Ä";
    printf("%d\n",*n); //before conversion printing -60, this is wrong should return 196
    int a=tolower((int)*n);
    printf("%d\n",a); //After conversion returns -60 which is really wrong.

    }
    From MSDN:
    Example

    /* TOUPPER.C: This program uses toupper and tolower to
    * analyze all characters between 0x0 and 0x7F. It also
    * applies _toupper and _tolower to any code in this
    * range for which these functions make sense.
    */
    And in your example the characters from the range between 0x7F and 0xFF are used!
    Victor Nijegorodov

  7. #7
    Join Date
    Jan 2007
    Posts
    143

    Wink Re: upper to lower case conversion.

    Is their any datatype available for storing special characters since decimal value of special characters are Ä=196 ä=228 etc.in c++ in windows

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: upper to lower case conversion.

    char, unsigned char - for ASCII,
    wchar_t - for UNICODE
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured