1,105,423 Community Members

alphabet from lower to upper , using ascii

Member Avatar
Xufyan
Posting Whiz
312 posts since Mar 2010
Reputation Points: -4 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

alphabet from lower to upper , using ascii
what logic should be use to convert small letters into capital using ascii codes??
for example ascci code for A is 65 and ascii code for a is 97
how can i coonvert from integers to character ?

Member Avatar
Banfa
Practically a Posting Shark
801 posts since Mar 2010
Reputation Points: 582 [?]
Q&As Helped to Solve: 134 [?]
Skill Endorsements: 12 [?]
Featured
 
0
 
int number = 65;
char letter = number;

There are no characters in C only integers with different ranges. A character is no more than a number that is interpreted by the display sub-systems to write pixels on the screen in a forum that you recognise as a letter.

Member Avatar
Adak
Posting Virtuoso
1,711 posts since Jun 2008
Reputation Points: 419 [?]
Q&As Helped to Solve: 207 [?]
Skill Endorsements: 10 [?]
 
1
 

What about using char ch = 'a'; and then ch++; 26 times?

char toCap = 'a';
toCap -= ('a' - 'A');

int integer = 0;
integer += 'a' for lowercase,

Now print it with a %c and with a %d :)

And what would it be to change an integer into uppercase?

Check out toupper() and tolower(), as well.

Member Avatar
xavier666
Junior Poster
147 posts since Sep 2009
Reputation Points: 56 [?]
Q&As Helped to Solve: 10 [?]
Skill Endorsements: 2 [?]
 
1
 

Do you know this feature of characters in C?

char ch = 'A';
ch = ch + 1;
printf("%c", ch);

Output

B

Now, you said ASCII code of 'A' = 65 & ASCII code of 'a' = 90, hence try to figure how much you should add/subtract from a character to convert into uppercase/lowercase

Member Avatar
WaltP
Posting Sage w/ dash of thyme
9,363 posts since May 2006
Reputation Points: 2,905 [?]
Q&As Helped to Solve: 1,151 [?]
Skill Endorsements: 45 [?]
Team Colleague
 
1
 

alphabet from lower to upper , using ascii
what logic should be use to convert small letters into capital using ascii codes??
for example ascci code for A is 65 and ascii code for a is 97
how can i coonvert from integers to character ?

Such confusing responses....

What is the difference (numerically) between 'A' and 'a'?
What about 'B' and 'b'?
'C' and 'c'?
Notice a pattern?

Therein lies your logic for conversion.

Member Avatar
Banfa
Practically a Posting Shark
801 posts since Mar 2010
Reputation Points: 582 [?]
Q&As Helped to Solve: 134 [?]
Skill Endorsements: 12 [?]
Featured
 
1
 

<pedantic>
Most of the above posts make the following assumptions

  1. 'B' - 'A' == 'C' - 'B' == ... == 'z' - 'y' == 1 and similarly for all letters that are adjacent in the alphabet.

  2. 'a' - 'A' == 'b' - 'B' == ... == 'z' - 'Z' and similarly for all lower case upper case letter pairs in the alphabet.

These relationships between the numeric values of letters are not a function of C (or C++) but rather a function of the execution character set in use, in this case ASCII. The C standard does not require the use of ASCII as the execution character set or in fact any particular character set and does not require the relationships 1 and 2 above. It does require that

'1' - '0' == '2' - '1' == '3' - '2' == '4' - '3' == '5' - '4' ==
'6' - '5' == '7' - '6' == '8' - '7' == '9' - '8' == 1

There are some character sets where the letters do not have contiguous character values EBCDIC is the example normally given where 'J' - 'I' == 8.

While a very large number of today's platforms use ASCII as their compilation and execution character set there are still some platforms (mobile phones spring to mind, or at least the SMS parts of them) that don't.

It is normally easy enough to get round this character set limitation using functions provided in ctype.h such as toupper.
</pedantic>

Member Avatar
Xufyan
Posting Whiz
312 posts since Mar 2010
Reputation Points: -4 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks alot everyone...!
through your Help i've done my Program and it is now converting the input alphabet into upper case :)

Question Answered as of 4 Years Ago by Banfa, WaltP, Adak and 1 other
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article