Copying Elements of arrays

I have to make a function that will copy the first row of instock to gamma. Can someone tell me if this is the correct way to do it. also, if I can modify this then please let me know. Not enough example was provided in my book.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  void copygamma(int stock[][4],int rowsizeofstock,int gam[],int gamasize, int copyfrom)
{
	int index=0;
	int row=1;
	for (int col=0;col<4;col++)
	{
		gam[index]=stock[row][col];
	
	
	}



}

int _tmain(int argc, _TCHAR* argv[])
{
	int instock[10][4];
	int alpha[20];
	int beta[20];
	int gamma[4]={11,13,15,17};
Remember that array indices start at 0, so the first row of stock is row 0. Also, you want to increment the index for gam[] as well, so either add an index++ in the for loop or just use col as the index.

Since you're passing in gamasize, you should also check that it is greater or equal to 4, or else you won't be able to copy over all the data.
Yup, I noticed myself that I had several basic errors in there. Thank you for pointing them out :)
Topic archived. No new replies allowed.