|
|
View previous topic :: View next topic |
Author |
Message |
deperkin
Joined: 04 Feb 2009 Posts: 83 Location: PA
|
strings in structs |
Posted: Mon Dec 17, 2012 7:51 pm |
|
|
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
|
brackets |
Posted: Mon Dec 17, 2012 8:36 pm |
|
|
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
|
another trial |
Posted: Mon Dec 17, 2012 9:38 pm |
|
|
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
|
|
Posted: Mon Dec 17, 2012 11:09 pm |
|
|
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
|
thanks |
Posted: Mon Dec 17, 2012 11:12 pm |
|
|
Thanks PCM programmer...
you are correct as usual!
I appreciate the help. |
|
|
|
|
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
|