Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fix "a parameter list without types is only allowed in a function definition"

I am trying to create a function that would take a name(string) that has been input by a user and compare it with a string within a custom data type/structure to verify that the name that the user has input exists in the memory.

The custom data type is set to be global and is as follows:

// Max number of candidates
#define MAX 9

// Candidates have name and vote count
typedef struct
{
    string name;
    int votes;
}
candidate;

// Array of candidates
candidate candidates[MAX];

The names of the different candidates are stored in the array candidates via a command line argument.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

After that the user is prompted to vote for a candidate by inserting the name of a candiate using:
string name = get_string("Vote: ");

which is then taken to this function to verify whether the candidate’s name exists or not.

Here is the function:

bool vote(string name)
{
    // TODO
    int i;
    string cn = candidates[i].name;
    for (i = 1; i < MAX; i++)
    {
        int strcmp(cn, name);
    }

    return strcmp;
}

However, I am not sure what the error means:

a parameter list without types is only allowed in a function definition
        int strcmp(cn, name);
                   ^

How can I fix this?

>Solution :

The strcmp() compares two strings character by character.

If the strings are equal, the function returns 0.

A simple way to use strcmp:

int returnValue = strcmp(cn, name);
if (returnValue == 0) {
    // string matched, so this name exists
}

Please check below 2 links to learn more about strcmp()

Another mistake to mention, you tried to access the ith candidate’s name from outside the loop.

You need to do it from inside.

For example:

for(int i = 0; i < MAX; i++) {
    string cn = candidates[i].name;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading