|
|
View previous topic :: View next topic |
Author |
Message |
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
Multiple array char variable |
Posted: Thu Aug 31, 2006 10:07 pm |
|
|
Ok, I'm going to look dumb here but I'm trying to use a char variable that has multiple strings in it. I've tried declaring it various ways but I guess I'm just stuck in neutral. I want to be able to have something like "Guest", "Owner", "Name" and so on stored inside the multiple array variable. Could one of you give me an example of how to declare it, that CCS will accept because it won't work the way my books show it, and how to initialize it with some of the strings.
Thanks
Ronald |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Thu Aug 31, 2006 11:23 pm |
|
|
Why did you copy to another string instead of referencing the original string in the printf parameter list?
Code: |
&weekday_names[dt.weekday]
|
_________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 01, 2006 1:06 am |
|
|
I couldn't get your method to work, but it does work without the
ampersand.
As far as why I didn't put it in the driver post -- I think it was because
I tried to pass the constant the array to printf and it wouldn't compile,
and so I just went with something that I knew would work. I was tired
of working on it and just wanted to get it done. I think that's the reason.
But the following code does work, without the strcpy():
Code: | #include <16F877.H>
#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
char const weekday_names[7][10] =
{
{"Sunday"},
{"Monday"},
{"Tuesday"},
{"Wednesday"},
{"Thursday"},
{"Friday"},
{"Saturday"}
};
typedef struct
{
int8 seconds; // 0 to 59
int8 minutes; // 0 to 59
int8 hours; // 0 to 23 (24-hour time)
int8 day; // 1 to 31
int8 month; // 1 to 12
int8 year; // 00 to 99
int8 weekday; // 0 = Sunday, 1 = Monday, etc.
}date_time_t;
//====================================
void main()
{
char i;
char weekday[10];
date_time_t dt;
for(i = 0; i < 7; i++)
{
dt.weekday = i;
printf("%s\n\r", weekday_names[dt.weekday]);
}
while(1);
} |
|
|
|
|
|
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
|