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

Multiple array char variable

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



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

Multiple array char variable
PostPosted: Thu Aug 31, 2006 10:07 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 31, 2006 10:34 pm     Reply with quote

The driver that I did for the PCF8583 has a two dimensional array of
"days of the week". I copy one day's name to a ram array and
then pass it to printf to be displayed:
http://www.ccsinfo.com/forum/viewtopic.php?t=27988

Here are two more threads on two dimensional arrays:
http://www.ccsinfo.com/forum/viewtopic.php?t=22130
http://www.ccsinfo.com/forum/viewtopic.php?t=20276
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Aug 31, 2006 11:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Sep 01, 2006 1:06 am     Reply with quote

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);
}
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