Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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:
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started