0

My code will compile, but I'm getting "linker code failed" on my custom function. So I'm not implementing this custom function as I intend to. I still have to deal with case sensitivity and non letters, but I'd like to work out what I did wrong first.

#include <ctype.h>
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


// points assigned to each letter of the alphabet
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();

int main(void)
{
    //get input 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 wins!!!");
    }
    else if ( score2 >  score1)
    {
        printf("player 2 wins!!!");
    }
    else if (score1 == score2)
    {
        printf("TIE!");
    
int compute_score();
    for (score1=0; score1< strlen(word1); score1++)
    {
        
       score1+= * (POINTS);
    }
    return score1;
    
    for (score2=0; score2 <strlen(word2); score2++)
    {
        score2+= *(POINTS);
    }
    return score2;
}
}     
1

You have declared your function incorrectly. It should not be within your main function. So, it should look like this:

int main(void)
{
    // code you want in the main function
}

int compute_score()
{
    // code you want in your compute_score function
}

You don't need the ; after the method declaration except for in the prototype declaration at the beginning. The actual function should look similar to the main function.

Hope that helps. If it does, feel free to click the check mark next to my answer. If not, let me know and I can try to help further.

3
  • that worked beautifully thank you. ive realized that my notes suck and i need to rewrite them. im not getting for loops to save my life and i think my logic is off, but i''l work it out
    – Aamon Van
    Mar 17 at 18:31
  • do you know what the difference between stack exchange, stack overflow and (i think its meta stack) is?
    – Aamon Van
    Mar 17 at 18:33
  • Regarding for loops, here is a pretty detailed answer I wrote for someone else a couple months ago that will hopefully help get the logic to make sense. Regarding the difference, I am only really active here, but they seem to all be a connected system of sites with different specific topics/focuses for organization. Each one seems to have it's own meta that is for asking questions about that forum. But, that is the most that I know and have gathered. Mar 17 at 18:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .