week 6
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int hash(char *word);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *word= get_string("Word: ");
|
||||
printf("Hash value: %i\n", hash(word));
|
||||
}
|
||||
|
||||
int hash(char *word)
|
||||
{
|
||||
if (word == NULL || strlen(word) == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
char c = word[0];
|
||||
if (isalpha(c))
|
||||
{
|
||||
c = toupper(c);
|
||||
return c -'A';
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user