Pages: [1]   Go Down
Author Topic: Converting char to upper case  (Read 3351 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

I need to convert a char to upper case.
I was trying char.toUpperCase(), but this function doesn't work for chars.

Is there an UpperCase function for chars?


Regards,
Atalanttore
Logged

Portugal
Offline Offline
God Member
*****
Karma: 6
Posts: 962
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, using this std c function:
int toupper    (    int     __c )

http://www.nongnu.org/avr-libc/user-manual/group__ctype.html#ga924ed052807e23cfa160d5f171cf5e2a
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

char one_char='f';
one_char=one_char-'a'-'A';

This is when you are sure the one_char is in lower case. Otherwise, do if statement.
Logged


Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 62
Posts: 2635
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

char one_char='f';
one_char=one_char-'a'-'A';

This is when you are sure the one_char is in lower case. Otherwise, do if statement.

But if you want to get down and dirty and assume ASCII and that the values are always
letters vs any possible character, and not use the ctype functions, then simply mask off
bit 5.

i.e.
Code:
upper_charvalue = charvalue & ~(0x20);

It won't matter if the charvalue is upper or lower case. But it will trash characters
that are not letters.

If you use the toupper() function, it will only convert lower case characters to upper case
and leave other characters alone.

--- bill
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 211
Posts: 13469
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
one_char=one_char-'a'-'A';

must be a +

one_char = one_char - 'a' + 'A';

----

Include <ctype.h>   -->  - http://www.nongnu.org/avr-libc/user-manual/group__ctype.html -

Then you have "all" char manipulators

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Forgot my parentheses  smiley-red
Logged


Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 211
Posts: 13469
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
parentheses 
Recently I read a product description of a calculator that used different colors for matching parentheses. Quite functional!
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Recently I read a product description of a calculator that used different colors for matching parentheses. Quite functional!

Good idea. I would like an editor/IDE, which uses different colors for matching parentheses.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Recently I read a product description of a calculator that used different colors for matching parentheses. Quite functional!

Good idea. I would like an editor/IDE, which uses different colors for matching parentheses.

They at least indicate the parentheses when you have cursor on one of them.
Logged


Pages: [1]   Go Up
Jump to: