question about array?
Author Message
question about array?

Quote:

> I need assign values from arr1to another array arr2 ->
> arr2[24]={0,1,2,3,4,5,............24} accordingly
> like  int arr2[0]=arr1[0];

What you want is to loop through each element of the array and assign each value
the same in each array. For example - in your array of 24 elements:

for(k = 0;. k < 24; k++)
arr1[k] = arr2[k];

Would work. Where k is a counter variable acting as the index, after each
repetition of the loop, k is incremented by one, thus cycling through all the
elements of the array.

/Cody

Thu, 27 Sep 2001 03:00:00 GMT
question about array?
I'm very new to C programm.
If someone knows:
I have int arr1[2]={01}; but tnis numbers dinamically changes like 02,03...
until it's get 24 like 24 hours a day.
I need assign values from arr1to another array arr2 ->
arr2[24]={0,1,2,3,4,5,............24} accordingly
like  int arr2[0]=arr1[0];
How to do this?

Fri, 28 Sep 2001 03:00:00 GMT
question about array?
Cody Caughlan schrieb:

Quote:

> > I need assign values from arr1to another array arr2 ->
> > arr2[24]={0,1,2,3,4,5,............24} accordingly

Be careful, because this is not exactly correct. For an array of size 24
you need 24 initialisers, not 25 as you indicate. IOW use 0 to 23.

Quote:
> > like  int arr2[0]=arr1[0];

> What you want is to loop through each element of the array and assign each value
> the same in each array. For example - in your array of 24 elements:

> for(k = 0;. k < 24; k++)
>     arr1[k] = arr2[k];

The concept is sound, but two little bugs managed to sneak in:
- there is a '.' after the first ';' in the "for"
- you got "arr1" and "arr2" the wrong way round in the assignment

Stephan
(initiator of the campaign against grumpiness in c.l.c)
(-: A brandnew excellent FAQ version has been released !!! :-)
(-: Get it: http://www.eskimo.com/~scs/C-faq/versions.html :-)

Fri, 28 Sep 2001 03:00:00 GMT
question about array?

Quote:

> > I need assign values from arr1to another array arr2 ->
> > arr2[24]={0,1,2,3,4,5,............24} accordingly
> > like  int arr2[0]=arr1[0];

> What you want is to loop through each element of the array and assign each value
> the same in each array. For example - in your array of 24 elements:

> for(k = 0;. k < 24; k++)
>     arr1[k] = arr2[k];

> Would work. Where k is a counter variable acting as the index, after each
> repetition of the loop, k is incremented by one, thus cycling through all the
> elements of the array.

> /Cody

It is possible, to use memcpy() too. For example,

int arr_dst[ SIZE ];
int arr_src[ SIZE ];

memcpy( (void *)arr_dest, (void *)arr_src, sizeof( int )*SIZE );

Fri, 28 Sep 2001 03:00:00 GMT
question about array?

Quote:
>It is possible, to use memcpy() too. For example,

>int arr_dst[ SIZE ];
>int arr_src[ SIZE ];

>memcpy( (void *)arr_dest, (void *)arr_src, sizeof( int )*SIZE );

Or more simply (and clearly):

memcpy(arr_dest, arr_src, sizeof arr_dest);

--
-----------------------------------------

-----------------------------------------

Fri, 28 Sep 2001 03:00:00 GMT

 Page 1 of 1 [ 5 post ]

Relevant Pages

Powered by phpBB® Forum Software