I am working on creating a game of scrabble. I have created a function to iterate through each letter and add it the points for each player. I keep running into an error when as I am trying to convert the word argument (which will be a string) into an array of characters.
Here is the error I am getting (I am using the CS50 IDE)
scrabble.c:44:27: error: incompatible pointer to integer conversion assigning to 'char' from 'string' (aka 'char *'); dereference with * [-Werror,-Wint-conversion]
wordarray[wordlength] = word;
^ ~~~~
*
#include <ctype.h>
#include <cs50.h>
#include <stdio.h>
#include <string.h>
// Points assigned to each letter of the alphabet
int POINTS[26] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10};
char LETTERS[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y' , 'z'};
int compute_score(string word);
int main(void)
{
// Get input words from both players
string word1 = get_string("Player 1: ");
string word2 = get_string("Player 2: ");
// Score both words
int score1 = compute_score(word1);
int score2 = compute_score(word2);
// Print the winner
if (score1 > score2) {
printf("Player 1 is the winner!");
} else if (score1 < score2) {
printf("Player 2 is the winner!");
} else {
printf("It is a tie!");
}
}
int compute_score(string word)
{
// TODO: Compute and return score for string
** //Turn word into an array of characters
int wordlength = strlen(word);
char wordarray[wordlength];
wordarray[wordlength] = word;**
//Placeholder for players total score
int playerscore = 0;
//Placeholder for index value
int index;
//Placeholder for word value
int wordvalue;
//Loop throught the word array
for (int i = 0; wordarray[i] < strlen(word); i++) {
//the current letter being iterated through. Convert it to lowercarse
char letter = tolower(wordarray[i]);
//iterate through all the letters in the alphabet
for (int j = 0; j < 25; j++) {
//if the letter is in the alphabet
if (letter == LETTERS[j]) {
//assign its index value to index
index = LETTERS[j];
}
}
//match letter with value of points, assign to wordvalue
wordvalue = POINTS[index];
//push the wordvalue to the total player score
playerscore += wordvalue;
}
//iterate through all letters and return the playerscore
return playerscore;
}