functions with 2d array argument
-
i am new on c++ i need to create a function with 2d array argument. i mean i can use the integer numbers in a 2d array in my function. And i also need to know how i can copy the information from the textboxes to a 2d array in vc++. i hope you will help me. thanks
-
i am new on c++ i need to create a function with 2d array argument. i mean i can use the integer numbers in a 2d array in my function. And i also need to know how i can copy the information from the textboxes to a 2d array in vc++. i hope you will help me. thanks
Adnan Merter wrote:
need to create a function with 2d array argument. i mean i can use the integer numbers in a 2d array in my function.
for instance
int f(int a[3][2])
{
int i,j;
for(i=0; i<3; i++)
for(j=0; j<2; j++)
printf("a[%d][%d]=%d\n", i, j, a[i][j]);
return 0;
}Adnan Merter wrote:
And i also need to know how i can copy the information from the textboxes to a 2d array in vc++.
What is your difficulty about? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Adnan Merter wrote:
need to create a function with 2d array argument. i mean i can use the integer numbers in a 2d array in my function.
for instance
int f(int a[3][2])
{
int i,j;
for(i=0; i<3; i++)
for(j=0; j<2; j++)
printf("a[%d][%d]=%d\n", i, j, a[i][j]);
return 0;
}Adnan Merter wrote:
And i also need to know how i can copy the information from the textboxes to a 2d array in vc++.
What is your difficulty about? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarkei have an array like x[5][5] and i need to use it as an argument in my function i know how i use 1d array. i can it by using pointers.
void display (int *p, int size) { int i; for (i = 0; i < size; ++i) printf("%-5d%-5d \n", p[i],&p[i]); } int main() { int a[5] = {3, 8, 7, 6, 10}; display(a, 5); return 0; }
but i dont know how ican use 2d arrays -
i have an array like x[5][5] and i need to use it as an argument in my function i know how i use 1d array. i can it by using pointers.
void display (int *p, int size) { int i; for (i = 0; i < size; ++i) printf("%-5d%-5d \n", p[i],&p[i]); } int main() { int a[5] = {3, 8, 7, 6, 10}; display(a, 5); return 0; }
but i dont know how ican use 2d arraysFor instance:
void display (int *p, int size0, int size1)
{
int i, j;for (i = 0; i < size0; i++)
for (j = 0; j< size1; j++, p++)
printf("%-5d \n", *p );
}int main()
{
int a[2][5] = {{3, 8, 7, 6, 10}, {6, 16, 14, 12, 20}};
display((int *)a, 2, 5);
}If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke