Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

assigning an int value to a char

I need to assign each letter of the alphabet to a value, starting with ‘a’ = 0; ‘b’ = 1,…, ‘z’ = 25. I could obviously go through and just do it one by one, but I am trying to figure out how to do it using a loop (or multiple loops if necessary). It seems like it should be easy, but I can’t seem to put it together.

I haven’t really tried much yet because I am having a hard time thinking of what I can try. I think I just need a couple tips on how to get started and usually once I get started and have the idea in my head I can figure it out from there.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

c - ‘a’ 

will do what you want
assuming c is lowercase.

This subtracts the ascii value of ‘a’
from that of the variable c,
giving the distance from ‘a’

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading