0

Im writing a funtion that takes string as a argument and gives back a integer. This function counts lenght of a string entered at the command line argument. I get an error :" incompatible pointer types passing 'string' (aka 'char *') to parameter of type 'string *' (aka 'char **') ". Could You help me on this.

My code:

// function declaration
int lenght_of_string( string argv[]);

int main (int argc, string argv[])
{
    // function call
    int z = lenght_of_string(argv[1]);

    printf("Lenght of agrv[1]: %i\n", z);

}
// definition of the function
int lenght_of_string(string argv[])
{
    int a = 0;
    for (int i = 0; argv[1][i]!='\0';i++)
    {
        a = i;
    }

        return a - 1;
}
0

The function does not, in fact, take "string as a argument". It takes an array of strings as the argument. That is what this notation [] denotes.

  • Thank You for Your hint.. I just removed [] from function call and got rid of errors. – RafalH123 Jul 15 '20 at 7:49

You must log in to answer this question.

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