| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Another string question
I want to add up the sum of a string and I was wondering how you do that? For example if a user inputs the word "dog" into a string. It should sum to 314 if you look at the ascii code table.
d = 100, o = 111, g = 103 |
|
#2
|
||||
|
||||
|
|
|
#3
|
||||
|
||||
|
Just a thought ICON but wont strlen only count the amount of characters in the string and not necessarily give you the ascii amount for it? But If you want to count the characters in a string in C++ you could also just use str.length() str being the string name!
Read this Highlander, I submited it in your last post on strings and libraries.strings
__________________
---Official Member Of The Itsacon Fan Club--- ![]() Give a man a fish and he will eat for a day. Teach a man to fish and he will sit in a boat all day drinking beer. Last edited by Geo.Garnett : December 2nd, 2005 at 07:19 PM. |
|
#4
|
||||
|
||||
|
Yes if you want to count the number of characters you could use strlen or the other one. I'm just using strlen to iterate over all characters in the string. The ascii value is retrieved in the sum += str[i]; part, str[i] being the ascii value of ith character
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Another string question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|