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  
 
 [ 5 post ] 

 Relevant Pages 

1. Question: extern *array and array[]

2. Newbie question about arrays

3. Newbie question: Making arrays bigger

4. Question about array

5. question about array of pointers to chars

6. Stupid question about array boundries

7. a question on array!

8. Question about arrays

9. question on arrays

10. Question about array initializers, const

11. Beginner Question : Filling Arrays from Text Files

12. Memory question (Large Arrays)

 

 
Powered by phpBB® Forum Software