CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Array Assignment on the fly? - SOLVED

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

Array Assignment on the fly? - SOLVED
PostPosted: Wed Dec 07, 2011 7:07 am     Reply with quote

Hi,

I want to know how can i initialize an array without resorting to loops.
i have a data set like:
Code:
{243, 14, 25, 39}

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

View user's profile Send private message

PostPosted: Wed Dec 07, 2011 1:18 pm     Reply with quote

strcpy() is for null-terminated strings, use memcpy() for arbitrary data.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 07, 2011 1:49 pm     Reply with quote

See this previous thread on the topic:
http://www.ccsinfo.com/forum/viewtopic.php?t=29142
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Dec 09, 2011 7:37 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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