Question: C PROGRAM FUNCTION The prototype for hash is int hash(char *); For this ODP, you are to write a function named hash which accepts a
C PROGRAM FUNCTION
The prototype for hash is
int hash(char *);

For this ODP, you are to write a function named "hash" which accepts a string and returns an integer. To calculate the hash, add the ASCII codes of each character in the string. Then reduce the final sum mod 31. Note that to add the ASCII codes, you can simply add each character (1.e. buffer[1]) to a running integer sum. Use "%" for reducing the sun. Here are some sample hashes: A: 3 (A has an ASCII value of 65, and 65%31=3) ABC: 12 (A, B and C have ASCII codes of 65, 66 and 67, 65+66+67=198 and 198%31=12) Hello: 4 HELLP: 1 HELLN: 30 Be careful in your testing: strings you read with fgets have a In appended to the end, which wil1 change the hash value
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
