Getting Value Of A String

This is a discussion on Getting Value Of A String within the C Programming forums, part of the General Programming Boards category; This is probably so easy I could slap myself, but I can't figure out how to do this and it ...

1. Getting Value Of A String

This is probably so easy I could slap myself, but I can't figure out how to do this and it is necessary for a larger program I am building. Assuming that each letter in the alphabet is represented by a value, i.e. A=1, B=2, etc., I need to figure out a way to get the value of the letters of a string by adding up all the letters in it, multiplying those by 3, adding up all the numbers in it, multiplying those by 5, and then adding the two values together. So for example, if I had the string "bad", the value of the string would be 2 + 1 + 4 = 3(7) = 21. If the string was "bad63", the value of the string would be 21 + 5(6 + 3) = 66. Get what I mean? The string itself is coming from an outside file. I'm sure this is a simple thing to do but programming isn't my strong suit and I can't seem to find an answer to my question. Thanks for any help anyone can give me.

2. Hint:

sum = 0;
for ( i = 0 ; i < strlen(string); i++ ) sum += string[i] - 'A' + 1;

3. What exactly does the "string[i] - 'A' + 1 do?

EDIT: Oh never mind, ASCII code. Figured it out. Thanks, that is easy. Now to go bash my head into a wall for not figuring that out on my own. I am in your debt.

4. Wait, does that work for when numbers are part of the string too, or am I going to have to do something extra for that?

5. there are macros in <ctype.h>, like isdigit() etc.

6. Originally Posted by penance
Wait, does that work for when numbers are part of the string too, or am I going to have to do something extra for that?
Something extra, but not terribly different.

Here's a link to an online ASCII chart. Notice the order of numbers, uppercase letters, and lowercase letters. The order is what allows Salem's hint to work. Also notice that numbers, uppercase letters, and lowercase letters have different numeric values (for example, 'A' != 'a').