You don't need to associate numbers; they are there already. If you go to Unicode, you find there already are numbers. In fact the computer doesn't store 'a'; it stores 0x61 (97 in decimal). You can use % 0x20 after 'a', or 'a' - 'a' + 1. Both will work, but will give very peculiar results for things which aren't letters. They produce an int result.
Joined: Nov 01, 2008
well dats ok but i m not looking for dat. actually i need to do a program in which i have to see dat if a char = a, then it reads d value stored at 0 in an array. similarly if it is b, then from position 1 and so on till z.
I have no idea what 'dats', 'm', or 'd' means. Data? monkey? dictation?
We really prefer folks to use real words here. Many of our visitors don't have English as a first language, so using shorthand like this makes understanding complex topics even MORE difficult.
Why do you need the value for 'a' to be in the 0th element in the array? Memory is cheap. Why not have an array with, say, 127 elements, and then just not use most of them? 'a' would refer to element 97, 'b' to 98, etc., with elements 0-96 emtpy.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Originally posted by Kanika Bansal: well [th]ats ok but i [a]m not looking for [th]at. actually i need to do a program in which i have to see [th]at if a char = a, then it reads [the] value stored at 0 in an array. similarly if it is b, then from position 1 and so on till z.
Unicode for the alphabet is linear. So... if you convert the letter to unicode, then subtract the unicode for "a", you will get zero for "a", one for "b", two for "c", etc.