1

I want to copy arr2 to arr and pass arr as a function paramater

void func(char * array)
{}

int main(void)
{
    int a;
    char arr[6][50];
    char arr2[][50]={"qweeeaa","bbbb","ffaa","eeaa","aaaa","ffaa"};

    for(a=0; a<6;a++)
    {
        strcpy(arr[a], arr2[a]);
    }

    func(arr);

    return 0;
}

But I can not pass arr as a function parameter. I get

[Warning] passing argument 1 of 'func' from incompatible pointer type [enabled by default]
[Note] expected 'char *' but argument is of type 'char (*)[50]'

I am using MinGW GCC 4.8.1

1
  • 2
    [c] 2D array parameter - I find it incredible to believe that search wouldn't yield something helpful. Commented Jul 8, 2015 at 9:11

1 Answer 1

4

The type you pass and the type the function expects do not match. Change the function to receive a pointer to an array:

void func(char (*array)[50])
{

}

Other problems:

1) You haven't declared a prototype for func() either. In pre-C99 mode, compiler would assume the function returns an int and this would cause problem. In C99 and C11, missing prototype makes your code invalid. So either declare the prototype at the top of the source file or move the function above main().

2) Include appropriate headers (<stdio.h> for printf etc).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.