• Post Reply Bookmark Topic Watch Topic
  • New Topic

character converting into number in 2D char array  RSS feed

 
Defa Lukman
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to convert all letters in a 2D char array into number. As results, I want a = 0, b=1, c=2, ... z=25.

Then, I tried this as part of my code:



The result of my code is not what I expected before.

From 'a' to 'j', it worked well. But, from 'k' until 'z' it didn't print expected number.

What's wrong with my code and what is the correct way to fix it?

I already researched in any resources about this but still didn't find any solution yet.
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since I don't see any code which is printing anything, it's hard for me to comment on what's being printed.

But anyway you just said it didn't print what you expected. So not only do I not see what it printed, I don't know what you expected either. Could you have a look at our FAQ page TellTheDetails and post some more information?
 
Steve Fahlbusch
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will not get results as you expect by casting the integer value (which you get by subtracting 'a') if you convert back to a char.

So if you want > 9 you need to place this into an integer array, not a char array.

-steve
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!