בתאריך יום ש*י,23 ביולי 2012 12:53:29 UTC+1, מאת Alter:
> Hi all
>
>
> How to pass a multidimensional array of string to a function?
>
>
>
void multidstringfunction(char **str, int *dims, int Ndims)
{
int i;
int width = 1;
/* let's print the strings along the major dimension */
assert(Ndims > 1);
/* we don't know how many other dimensions there are, so we've got to
work out the block width */
for(i=1;i<Ndims;i++)
width *= dims[i];
/* now we can get the string at [i, 0, 0, 0 ...] by multiplying
by width */
for(i=0;i<dims[0];i++)
printf("string %d - %s\n", str[i*width];
}
|