|
|
View previous topic :: View next topic |
Author |
Message |
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
Assign an array value to variable |
Posted: Thu Jul 10, 2014 10:42 pm |
|
|
Dear all,
I have an array such as
Now i have another variable and i want to assigned the value of array 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
|
|
Posted: Thu Jul 10, 2014 11:42 pm |
|
|
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
|
|
Posted: Thu Jul 10, 2014 11:42 pm |
|
|
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
|
|
Posted: Fri Jul 11, 2014 5:14 pm |
|
|
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
|
|
Posted: Fri Jul 11, 2014 5:22 pm |
|
|
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},
};
|
|
|
|
|
|
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
|