0

I hate to ask again because this should be incredibly simple, but I'm literally running strcmp(name, candidates[j].name) and it is telling me candidates[j].name is an int in the error and not a char so it won't run. What's frustrating is that I'm sure, based on my past psets, that it isn't going to work right the first time, but I can't even test the code to start to debug because it won't compile

The cs50 code itself literally defines candidates[i].name as a string (I know there is i and j issues, but it doesn't matter. 1) I tried i and it didn't help and 2) they are both variables for "for loops")

For reference, this is the relevant code and error message:

typedef struct
{
    string name;
    int votes;
    bool eliminated;
}
candidate;
...
bool vote(int voter, int rank, string name)
{
    // TODO
    for (int i = 0; i < voter_count; i++)
    {
        for (int j = 0; j < candidate_count; j++)
        {
            if (strcmp(name, candidates[j].name == 0))
...

runoff.c:136:30: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *' [-Werror,-Wint-conversion] if (strcmp(name, candidates[j].name == 0))

0

Without seeing the declaration code for candidates, I can't be 100% sure, but I'm hovering around 99% right now. ;-)

Look at the line in question:

 if (strcmp(name, candidates[j].name == 0))

It's comparing name to the result of candidates[j].name == 0 which evaluates to 1 or 0, both of which are ints. I'd say you incorrectly placed a paranthesis. Try this:

 if (strcmp(name, candidates[j].name) == 0 )

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

| improve this answer | |

You must log in to answer this question.

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