From a664bf7383b41c5f266485454154b516e4d1e164 Mon Sep 17 00:00:00 2001 From: Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> Date: Mon, 29 Apr 2024 02:13:57 +0000 Subject: Sun, Apr 28, 2024, 7:13 PM -07:00 --- wk5/pset/speller/test.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 wk5/pset/speller/test.c (limited to 'wk5/pset/speller/test.c') diff --git a/wk5/pset/speller/test.c b/wk5/pset/speller/test.c new file mode 100644 index 0000000..1b03355 --- /dev/null +++ b/wk5/pset/speller/test.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include +#include +#include + +// Hashes word to a number +int main(void) +{ + char *word = "cat"; + // (sum of (letter - 'A') % 26) of a word to get a value of where to store it in the hash table + int val = 0; + for (int i = 0; word[i] != '\0'; i++) + { + val += toupper(word[i]) - 'A'; + } + return val %= 26; +} -- cgit v1.2.3