My code is below:
#include <ctype.h>
#include <cs50.h>
#include <stdio.h>
#include <string.h>
int points[] = {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};
int compute_score(string word);
int main(void)
{
string word1 = get_string("Player 1: ");
string word2 = get_string("Player 2: ");
int score1 = compute_score(word1);
int score2 = compute_score(word2);
if (score1 > score2)
{
print("Player 1 wins! \n");
}
else if (score2 > score1)
{
print("Player 2 wins! \n");
}
else
{
print("Tie! \n");
}
}
int compute_score(string word)
{
int score = 0;
for (int i = 0, len = strlen(word); i < len; i++)
{
if isupper(word[i])
{
score += points[word[i] - "A"];
}
else
{
score += points[word[i] - "a"];
}
}
return score;
}
I expected it to execute, and I still don't know why it didn't. It keeps saying "Permission denied" when I try to run the file, although the "make" function works fine. Any ideas?
It's because you don't have
Execution Permissionfor the file.If you do
ls -layou see somthing like this:The left part
drwxr-xr-xtell information about the file.The
dat start is forDirectory, andrwxis forread,write&execution.You have 3 time's
rwx, in order is forUser,group,other.You can change the file Permission with
chmodcommand.For more info use
chmod --helpor/andman chmod.when you use
make, that call aMakefileand he set that permission for you.