0

bool vote(int voter, int rank, string name) { // TODO

for(voter=0;voter<=voter_count;voter++)
{
    for(rank=0;!strcmp(name, candidates[rank].name == 0);rank++)
    {
            preferences[voter][rank] = rank;
    }
}
    return false;

I was doing runoff and this error comes to me what's the problem ?

incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *' [-Werror,-Wint-conversion] for(rank=0;!strcmp(name, candidates[rank].name == 0);rank++)

/usr/include/string.h:136:50: note: passing argument to parameter '__s2' here extern int strcmp (const char *__s1, const char *__s2)

1 Answer 1

2

looking at this part of it:

strcmp(name, candidates[rank].name == 0)

I'd say that the closing parenthesis is in the wrong place. The compiler doesn't know what to do with a test condition as a parameter to a function call.

Try putting the ) before the == instead of after the 0.

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

[EDIT - almost 4 years later]

You could also simplify it as follows:

for(rank=0;strcmp(name, candidates[rank].name);rank++)

This simplification works because C will always treat a value of 0 as false (and anything else, positive or negative, as true). The strcmp() function will return 0 when the values are the same and a non-zero when they're not. Since you want the loop to continue as long as the two strings don't match (meaning a non-zero value is returned), it works.

You must log in to answer this question.

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