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 CCS Technical Support

Assign an array value to variable

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



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

Assign an array value to variable
PostPosted: Thu Jul 10, 2014 10:42 pm     Reply with quote

Dear all,

I have an array such as

Code:
varia[2] ={5,45}


Now i have another variable
Code:
int8 knife
and i want to assigned the value of array
Code:
varia[1]
by make the following statement but for some reason it is not working. The variable is remaining as 0

Code:
int8 knife = varia[1];


Can someone tell me what i am making wrong, maybe i am missing something.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 10, 2014 11:42 pm     Reply with quote

Just do it like this and then it will work:
Code:
void main()
{
int8 varia[2] ={5,45};
int8 knife;

knife = varia[1];


while(1);
}
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Thu Jul 10, 2014 11:42 pm     Reply with quote

At compile time the comlier only works with literals, knows nothing about what are in "PIC memory".

Why not use a #define VAL 45
then varia[2]= {5, VAL}
int8 knife=VAL

Regards
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Fri Jul 11, 2014 5:14 pm     Reply with quote

Thanks PCM and Alan for your kind help. Everything worked fine now. Just to let you know that the first time I forgot to put the the routine in function. But now it ok.

To make the second step, I am creating two arrays such below. I am right if i say that if I create two-dimensional array I can increment the first coordinate [i] to load the second array in the memory?

Code:
int8 alarm[1][7] = {11,7,14,4,0,6,05};
int8 alarm[2][7] = {11,7,14,4,0,8,05};


Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 11, 2014 5:22 pm     Reply with quote

No, you don't initialize a 2-dimensional array like that. Do it like this:
Code:

int8 alarm[2][7] = {
{11,7,14,4,0,6,05},
{11,7,14,4,0,8,05},
};
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