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

structures in CCS

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



Joined: 09 Dec 2009
Posts: 37

View user's profile Send private message

structures in CCS
PostPosted: Tue May 18, 2010 2:55 am     Reply with quote

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
collink



Joined: 08 Jan 2010
Posts: 137
Location: Michigan

View user's profile Send private message Visit poster's website

Re: structures in CCS
PostPosted: Tue May 18, 2010 11:13 am     Reply with quote

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.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed May 19, 2010 2:06 am     Reply with quote

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.
smanzer



Joined: 14 Sep 2009
Posts: 24
Location: Ontario, Canada

View user's profile Send private message Visit poster's website

PostPosted: Sun May 23, 2010 8:59 pm     Reply with quote

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
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon May 24, 2010 2:15 am     Reply with quote

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.
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