Thread: I Need Help

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    7

    Angry I Need Help

    Can anyone teach me how to find total ASCII value in a char array?

    For example:
    in the array contains: abc
    it will esrach for ASCII value for a,b and c
    then it will add up all the value
    can anyone teach me this?

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Just add the values of the characters in the array:
    Code:
    char array[] = "abc";
    int total = array[0] + array[1] + array[2];
    This would be 97 + 98 + 99 or 294!
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    170
    Code:
    char array[] = "abc";
    int total=0, i;
    
    for( i=0; i < strlen( array ); i++)
         total += array[i];

Popular pages Recent additions subscribe to a feed