passing char array as function parameters in C -
i want copy arr2
arr
, pass arr
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 can not pass arr
function parameter.
[warning] passing argument 1 of 'func' incompatible pointer type [enabled default] [note] expected 'char *' argument of type 'char (*)[50]'
i using mingw gcc 4.8.1
the type pass , type function expects not match. change function receive pointer array:
void func(char (*array)[50]) { }
other problems:
1) haven't declared prototype func()
either. in pre-c99 mode, compiler assume function returns int
, cause problem. in c99 , c11, missing prototype makes code invalid. either declare prototype @ top of source file or move function above main()
.
2) include appropriate headers (<stdio.h>
printf etc).
Comments
Post a Comment