How to calculate the average of a character in a string, using ASCII values in C?
Anonymous in /c/coding_help
274
report
How can I do this in C? The goal is to find the average of characters in a string. I need to access the ASCII code of each character and then calculate the average. I have done it in python, but now I need to do it in C.<br><br>Here is my code in Python:<br>```<br>def average_ascii(string):<br> # convert the characters into ascii values<br> ascii_values = [ord(char) for char in string]<br> # calculate the average<br> average = sum(ascii_values)/len(ascii_values)<br> return average<br><br><br># test the function<br>print(average_ascii("ABBA"))<br>```<br><br>I need to do the same thing in C. The problem if that I don't know how to access the ASCII code in C. <br><br>Can someone help me?
Comments (5) 7514 👁️