Question: Need help creating the following hash function in C: For this ODP, you are to write a function named hash which accepts a string and

Need help creating the following hash function in C:

Need help creating the following hash function in C: For this ODP,

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 (i.e. buffer[1]) to a running integer sum. Use "%" for reducing the sum. 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: 0 Hello: 4 HELLP: 1 HELLN: 30 Be careful in your testing: strings you read with fgets have a In appendeod to the end, which will change the hash value. The prototype for hash is int hash(char

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!