Originally Posted by
B-Con
I'm writing a C program and I need to pass an array with 2 dementions to a function, but I don't know how to declare it as an arguement in the function parameters....
I'll pass, depending, either element "catagory[0]" or "catatory[1]", both have 5 elements in the 2nd demention, but within the function I need to be able to access either of them with the same receiving arguement, ie:
Is the following close to what you are describing?
Code:
#include <stdio.h>
void foo(const char (*bar)[5])
{
size_t i;
for ( i = 0; i < sizeof *bar / sizeof **bar; ++i )
{
printf("%c", bar[0][i]);
}
putchar('\n');
for ( i = 0; i < sizeof *bar / sizeof **bar; ++i )
{
printf("%c", bar[1][i]);
}
putchar('\n');
}
int main (void)
{
const char ked[][5] =
{
{'a','b','c','d','e'},
{'f','g','h','i','j'},
};
foo(ked);
return 0;
}
/* my output
abcde
fghij
*/