|
|
View previous topic :: View next topic |
Author |
Message |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
Array Assignment on the fly? - SOLVED |
Posted: Wed Dec 07, 2011 7:07 am |
|
|
Hi,
I want to know how can i initialize an array without resorting to loops.
i have a data set like:
when i declare my array:
Code: | Int Device[4]={243, 14, 25, 39}; |
its all good..
But if later down the code i want to "Device[]" to have diferent values
what would be the _working_ equivalent of this:
Code: | Device[]={155, 26, 35, 49}; |
The values in each possition of "Device[]" change depending on the function called...
So far my solution has been to declare several:
Code: | Const Int Temp1[4]={1,2,3,4} ....
Const Int Temp2[].... |
arrays with the values i want, and then:
Code: | STRCPY(Device, Temp1);...
STRCPY(Device, Temp2);... |
Depending on which function needs to use Device[]...
The actual size of Device is [75].
is there a better way? _________________ CCS PCM 5.078 & CCS PCH 5.093
Last edited by Gabriel on Fri Dec 09, 2011 7:37 am; edited 1 time in total |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Dec 07, 2011 1:18 pm |
|
|
strcpy() is for null-terminated strings, use memcpy() for arbitrary data. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Fri Dec 09, 2011 7:37 am |
|
|
hey guys,
Thanks for your replies...
I see I was not too far off...
STRCPY is working for me right now, however I will change to MEMCPY.
Thanks!
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|