View previous topic :: View next topic |
Author |
Message |
assaad
Joined: 09 Dec 2009 Posts: 37
|
structures in CCS |
Posted: Tue May 18, 2010 2:55 am |
|
|
Hi all
I am new to ccs and trying to learn it ,
I have wote this code to learn how structures work
Code: |
struct motor {
CHAR name[10];
CHAR type[10];
INT speed[7];
UNSIGNED CHAR location[15];
};
struct motor dc_motor1;
void main()
{
dc_motor1.name="drase";
dc_motor1.type="bmotor";
dc_motor1.speed=3800;
dc_motor1.location="sweden";
|
But when I compile it it gives me an error:
Quote: |
Expecting LVALUE such as a variable name or * expression
|
Could you help please to solve it ?
Thank you |
|
![](templates/subSilver/images/spacer.gif) |
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
Re: structures in CCS |
Posted: Tue May 18, 2010 11:13 am |
|
|
Which chip are you using and which compiler?
If I copy your code into a file on my end and pretend you were using a PIC18F2685 with compiler version 4.105 it has no errors. |
|
![](templates/subSilver/images/spacer.gif) |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Wed May 19, 2010 2:06 am |
|
|
The ability to copy a string into a char array using =
dc_motor1.name="drase";
has only recently been introduced into the CCS compiler. It is not C compliant.
To do it in C you would use strcpy, sprintf, memcpy or some other method where you loop through the array :-
strcpy(dc_motor1.name, "drase");
I am not sure if this is your problem though as we don't know what version of compiler you are using. |
|
![](templates/subSilver/images/spacer.gif) |
smanzer
Joined: 14 Sep 2009 Posts: 24 Location: Ontario, Canada
|
|
Posted: Sun May 23, 2010 8:59 pm |
|
|
Hi assaad,
The version number of any compiler has little to do with your question. Google struct and you will see lots of info like linked lists etc.
strcpy(dc_motor1.name,"drase");
// Should work fine...depending on how
// you define the struct, you may need:
strcpy(dc_motor1->name, "drase");
Keep at it, C is good, PIC's are great, and together they are amazing.
Steven _________________ "I am always doing that which I can not do, in order that I may learn how to do it."
- Pablo Picasso |
|
![](templates/subSilver/images/spacer.gif) |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Mon May 24, 2010 2:15 am |
|
|
smanzer wrote: | Hi assaad,
The version number of any compiler has little to do with your question. Google struct and you will see lots of info like linked lists etc.
Steven |
Me wrote: |
The ability to copy a string into a char array using =
dc_motor1.name="drase";
has only recently been introduced into the CCS compiler. It is not C compliant.
|
If he is using the latest version of the compiler then :-
Code: | dc_motor1.name="drase"; |
Should work and the problem lies elsewhere. |
|
![](templates/subSilver/images/spacer.gif) |
|