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

strings in structs

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



Joined: 04 Feb 2009
Posts: 83
Location: PA

View user's profile Send private message Send e-mail

strings in structs
PostPosted: Mon Dec 17, 2012 7:51 pm     Reply with quote

general C question if anyone can help please (using v4.114):

I want to create a struct:
Code:

struct TestInput{
   int8     count;
   int8     addr;
   int8     port;
   int8     mask;
   int8     func;
   int16    conn; 
   char     cavity[2];
   char     circuit[4];
   char     description[50];
};

I plan on having alot of these and in Main() will this be the correct format:
Code:
struct TestInput FWAClutch;

FWAClutch = 2,6,18,1,0,39,6,"3115","MIXER & FWA CLUTCH";

I have tried this:
Code:

struct TestInput FWAClutch = 2,6,18,1,0,39,6,"3115","MIXER & FWA CLUTCH";

and I get errors.
I just want to make sure the correct numbers are showing up in the struct correctly.
Unfortunately when I try this:
Code:

struct TestInput FWAClutch;

FWAClutch = 2,60000000000000,18,1,0,39,6,"3115","MIXER & FWA CLUTCH";

I still get it to compile with the same RAM/ROM size....


Thanks for the help.


Last edited by deperkin on Mon Dec 17, 2012 8:59 pm; edited 2 times in total
deperkin



Joined: 04 Feb 2009
Posts: 83
Location: PA

View user's profile Send private message Send e-mail

brackets
PostPosted: Mon Dec 17, 2012 8:36 pm     Reply with quote

If I try this:

Code:
struct TestInput FWAClutch;
   
FWAClutch = {2,6,18,1,0,39,6,"3115","MIXER & FWA CLUTCH"};


I get the error: "A numerical expression must appear here." and highlights the first curly bracket.
deperkin



Joined: 04 Feb 2009
Posts: 83
Location: PA

View user's profile Send private message Send e-mail

another trial
PostPosted: Mon Dec 17, 2012 9:38 pm     Reply with quote

I have also tried this:

Code:
struct _TestInput{
   int8     count;
   int8     addr;
   int8     port;
   int8     mask;
   int8     func;
   int16    conn; 
   char     cavity[2];
   char     circuit[4];
   char     description[50];
};

struct _TestInput FWAClutch = { 2, 6, 18, 1, 0, 39, 6, "3115", "MIXER & FWA CLUTCH" };


following some examples and I get an error "Expression must evaluate to a constant" and it highlights the comma after "3115"

also just a note, it doesnt seem to make a difference if I use typedef
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 17, 2012 11:09 pm     Reply with quote

The program shown below compiles OK with vs. 4.114.
I fixed it mainly by putting braces around all the array init values.

Other comments:
1. You are not allowing enough room in the circuit[] array for the
string terminator byte. I increased the size by 1 to allow for this.

2. You are not initializing the 2nd element in the cavity[] array.
The compiler will then initialize it for you, by setting it to 0.
Code:

#include <18F4520.h>
#fuses INTRC_IO,NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

struct _TestInput{
   int8     count;
   int8     addr;
   int8     port;
   int8     mask;
   int8     func;
   int16    conn; 
   char     cavity[2];
   char     circuit[5];   
   char     description[50];
};

struct _TestInput FWAClutch = { 2, 6, 18, 1, 0, 39, {6}, {"3115"}, {"MIXER & FWA CLUTCH"} };


//=========================================
void main() 
{


while(1); 
}
deperkin



Joined: 04 Feb 2009
Posts: 83
Location: PA

View user's profile Send private message Send e-mail

thanks
PostPosted: Mon Dec 17, 2012 11:12 pm     Reply with quote

Thanks PCM programmer...

you are correct as usual!

I appreciate the help.
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