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

How to use multi dimentional array

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







How to use multi dimentional array
PostPosted: Tue May 20, 2003 11:37 am     Reply with quote

Can some one help,

I have the next structure and array. What ways can I use to copy an element of Modulo_Index to the Structure Red_Modulo.


char const Modulo_Index[3][4] =
{{0x00, 0x00, 0x00, 0x00},
{0x00, 0x01, 0x00, 0x00},
{0x01, 0x00, 0x01, 0x00}};

typedef struct {
char First;
char Second;
char Thirdth;
char Fourth;
}RGB_Modulo;


RGB_Modulo Red_Modulo;
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514597
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: How to use multi dimentional array
PostPosted: Tue May 20, 2003 1:51 pm     Reply with quote

:=Can some one help,
:=
:=I have the next structure and array. What ways can I use to copy an element of Modulo_Index to the Structure Red_Modulo.
:=
:=
:=char const Modulo_Index[3][4] =
:= {{0x00, 0x00, 0x00, 0x00},
:= {0x00, 0x01, 0x00, 0x00},
:= {0x01, 0x00, 0x01, 0x00}};
:=
:=typedef struct {
:= char First;
:= char Second;
:= char Third;
:= char Fourth;
:= }RGB_Modulo;
:=
:=
:=RGB_Modulo Red_Modulo;

-----------------------------------------------

Red_Modulo.First = Modulo_Index[0][0];
Red_Modulo.Second = Modulo_Index[0][1];
Red_Modulo.Third = Modulo_Index[0][2];
Red_Modulo.Fourth = Modulo_Index[0][3];
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514600
R.J.Hamlett
Guest







Re: How to use multi dimentional array
PostPosted: Tue May 20, 2003 2:57 pm     Reply with quote

:=Can some one help,
:=
:=I have the next structure and array. What ways can I use to copy an element of Modulo_Index to the Structure Red_Modulo.
:=
:=
:=char const Modulo_Index[3][4] =
:= {{0x00, 0x00, 0x00, 0x00},
:= {0x00, 0x01, 0x00, 0x00},
:= {0x01, 0x00, 0x01, 0x00}};
:=
:=typedef struct {
:= char First;
:= char Second;
:= char Thirdth;
:= char Fourth;
:= }RGB_Modulo;
:=
:=
:=RGB_Modulo Red_Modulo;
This line makes no sense. If you want to use 'RGB_Modulo', as a new 'type', you will need to use a typedef.

RGB_Modulo.First=Modulo_Index[0][0];

This will copy the first element in the array, into the first entry in the structure.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514601
Gerrit
Guest







Re: How to use multi dimentional array
PostPosted: Tue May 20, 2003 3:15 pm     Reply with quote

Hello PCM programmer,

What you sugested I have tested and that works.

What I want to know is if I can use a single element from
Modulo_Index[x] to palce in the structur Red_Modulo (all four
value's)


CCS if giving no error or warning on this

Red_Modulo = Modulo_Index[x];

What am I doing here? cant figger it out.


Regards,

Gerrit



:=:=Can some one help,
:=:=
:=:=I have the next structure and array. What ways can I use to copy an element of Modulo_Index to the Structure Red_Modulo.
:=:=
:=:=
:=:=char const Modulo_Index[3][4] =
:=:= {{0x00, 0x00, 0x00, 0x00},
:=:= {0x00, 0x01, 0x00, 0x00},
:=:= {0x01, 0x00, 0x01, 0x00}};
:=:=
:=:=typedef struct {
:=:= char First;
:=:= char Second;
:=:= char Third;
:=:= char Fourth;
:=:= }RGB_Modulo;
:=:=
:=:=
:=:=RGB_Modulo Red_Modulo;
:=
:=-----------------------------------------------
:=
:=Red_Modulo.First = Modulo_Index[0][0];
:=Red_Modulo.Second = Modulo_Index[0][1];
:=Red_Modulo.Third = Modulo_Index[0][2];
:=Red_Modulo.Fourth = Modulo_Index[0][3];
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514602
Gerrit
Guest







Re: How to use multi dimentional array
PostPosted: Tue May 20, 2003 3:16 pm     Reply with quote

Hello PCM programmer,

What you sugested I have tested and that works.

What I want to know is if I can use a single element from
Modulo_Index[x] to palce in the structur Red_Modulo (all four
value's)


CCS if giving no error or warning on this

Red_Modulo = Modulo_Index[x];

What am I doing here? cant figger it out.


Regards,

Gerrit



:=:=Can some one help,
:=:=
:=:=I have the next structure and array. What ways can I use to copy an element of Modulo_Index to the Structure Red_Modulo.
:=:=
:=:=
:=:=char const Modulo_Index[3][4] =
:=:= {{0x00, 0x00, 0x00, 0x00},
:=:= {0x00, 0x01, 0x00, 0x00},
:=:= {0x01, 0x00, 0x01, 0x00}};
:=:=
:=:=typedef struct {
:=:= char First;
:=:= char Second;
:=:= char Third;
:=:= char Fourth;
:=:= }RGB_Modulo;
:=:=
:=:=
:=:=RGB_Modulo Red_Modulo;
:=
:=-----------------------------------------------
:=
:=Red_Modulo.First = Modulo_Index[0][0];
:=Red_Modulo.Second = Modulo_Index[0][1];
:=Red_Modulo.Third = Modulo_Index[0][2];
:=Red_Modulo.Fourth = Modulo_Index[0][3];
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514603
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: How to use multi dimentional array
PostPosted: Tue May 20, 2003 4:01 pm     Reply with quote

:=What you sugested I have tested and that works.
:=
:=What I want to know is if I can use a single element from
:=Modulo_Index[x] to palce in the structur Red_Modulo (all four
:=value's)
:=
:=CCS if giving no error or warning on this
:=
:= Red_Modulo = Modulo_Index[x];
:=
----------------------------------------------------
It gives me an error. It says "Bad expression syntax".
That's with PCM vs. 3.148.

Modulo_Index is defined as a two-dimensional array,
but you're trying to use it as a one-dimensional array.
So that's why it gives the error.

What's wrong with using the method of copying the bytes
that I posted ? Are you looking for a method that
only takes one line of C code, or is there some other reason ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514606
Gerrit
Guest







Re: How to use multi dimentional array
PostPosted: Tue May 20, 2003 5:23 pm     Reply with quote

No not pritacarly looking for a one line command
but, what I'm doing wrong or why CCS is not
reporting an error.
It has taken me a lot of time testing today And I could not explain what I was doing wrong.

The line I used copied 3 variables to the structure. I'am
using Version 3.152, 18034.


I will modify my software tomorrow at work.


Thanks for the response


reagrds,


Gerrit

:=:=What you sugested I have tested and that works.
:=:=
:=:=What I want to know is if I can use a single element from
:=:=Modulo_Index[x] to palce in the structur Red_Modulo (all four
:=:=value's)
:=:=
:=:=CCS if giving no error or warning on this
:=:=
:=:= Red_Modulo = Modulo_Index[x];
:=:=
:=----------------------------------------------------
:=It gives me an error. It says "Bad expression syntax".
:=That's with PCM vs. 3.148.
:=
:=Modulo_Index is defined as a two-dimensional array,
:=but you're trying to use it as a one-dimensional array.
:=So that's why it gives the error.
:=
:=What's wrong with using the method of copying the bytes
:=that I posted ? Are you looking for a method that
:=only takes one line of C code, or is there some other reason ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514608
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: How to use multi dimentional array
PostPosted: Tue May 20, 2003 5:38 pm     Reply with quote

:=No not pritacarly looking for a one line command
:=but, what I'm doing wrong or why CCS is not
:=reporting an error.
:=It has taken me a lot of time testing today And I could not explain what I was doing wrong.
:=
:=The line I used copied 3 variables to the structure. I'am
:=using Version 3.152.
----------------------------------------------------

I installed PCM vs. 3.152 and it gave me an error message:
"Bad expression syntax".

But 3.152 has got some serious problems. For example, it
will not give an error if you're missing a closing brace.
I just did a test right now. I removed the closing brace
from main(). It didn't complain at all.

I would switch to either vs. 3.148 or 3.158, if you're able to.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514609
Woody
Guest







Arrays of structures
PostPosted: Wed May 21, 2003 4:43 am     Reply with quote

<font face="Courier New" size=-1>In order to assign values to the whole structure in one go you will need to change your array to an array of structures, rather than a two dimensional array. ( Unless it needs to be a two dimensional array for some other reason. )

#include <16f876.h>

typedef struct {
char First;
char Second;
char Third;
char Fourth;
} RGB_Modulo;

const RGB_Modulo Modulo_Index [3] = {
{0x00, 0x00, 0x00, 0x00},
{0x00, 0x01, 0x00, 0x00},
{0x01, 0x00, 0x01, 0x00}
};

RGB_Modulo Red_Modulo;

void main (void)
{
Red_Modulo = Modulo_Index [1];
}</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514625
Gerrit
Guest







Re: Arrays of structures
PostPosted: Wed May 21, 2003 6:31 am     Reply with quote

Hello woody,

This is what I was looking for.

I'm already correcting the arrays.


Thanks for the example

Regards,

Gerrit


:=In order to assign values to the whole structure in one go you will need to your array to an array of structures, rather than a two dimensional array. ( Unless it needs to be a two dimensional array for some other reason. )
:=
:=#include <16f876.h>
:=
:=typedef struct {
:= char First;
:= char Second;
:= char Third;
:= char Fourth;
:=} RGB_Modulo;
:=
:=const RGB_Modulo Modulo_Index [3] = {
:= {0x00, 0x00, 0x00, 0x00},
:= {0x00, 0x01, 0x00, 0x00},
:= {0x01, 0x00, 0x01, 0x00}
:=};
:=
:=RGB_Modulo Red_Modulo;
:=
:=void main (void)
:={
:= Red_Modulo = Modulo_Index [1];
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514628
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