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

Creating a string table...

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



Joined: 08 Dec 2005
Posts: 8

View user's profile Send private message

Creating a string table...
PostPosted: Wed Dec 21, 2005 1:59 pm     Reply with quote

Hello

I want to store several strings in a table. This is for displaying "info" screens on a graphic lcd.
I have no problem displaying

char info[]="Hello, this is the info screen";
glcd_putc(info);



I want to declare something like:

char info[][x]="skjdkhfs","sijdfhskd","jskdhfk";

And be able to to do f.ex
glcd_putc(info[1]);
glcd_putc(info[2]);

and so on..

Tried alot of things, but get tons of errors..

Is it possible to create a table with lets say 10 elements of 50 chars?

Thanks in advance
LT
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Wed Dec 21, 2005 2:29 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=25234

This thread has a method of doing what you wish, but in a different way.
LTS



Joined: 08 Dec 2005
Posts: 8

View user's profile Send private message

PostPosted: Wed Dec 21, 2005 2:42 pm     Reply with quote

Hmm, ok, i guess i could use that method, but is there no way to create a simple table of strings, and then use simple indexes "info[x]" to reach?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 21, 2005 2:46 pm     Reply with quote

Quote:
but is there no way to create a simple table of strings, and then use simple indexes "info[x]" to reach?

Here is one example. It displays:

Quote:

ABCD
Hello
Hi there
123456789


Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define NUM_STRINGS 4
#define STRING_BUF_SIZE 10

const char array[NUM_STRINGS][STRING_BUF_SIZE] =
{
{"ABCD"},
{"Hello"},
{"Hi there"},
{"123456789"}
};



void main()

int8 i;
int8 j;
int8 c;


for(i = 0; i < NUM_STRINGS; i++)
   {
    for(j = 0; j < STRING_BUF_SIZE; j++)
       {
        c = array[i][j];
        if(c == 0)  // If reached end of string
          {
           putc(10);  // then display CRLF and break
           putc(13);
           break;
          }
        else
          putc(c);   
       }
   }

while(1);
}
LTS



Joined: 08 Dec 2005
Posts: 8

View user's profile Send private message

PostPosted: Wed Dec 21, 2005 2:54 pm     Reply with quote

Great, thats exactly what i meant.. but.. how many elements and how many chars per element can i use? I really need each element to contain between 50-100 chars..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 21, 2005 3:13 pm     Reply with quote

Unfortunately, you can't do it. CCS says this in the manual:
Quote:
ROM arrays may not occupy more than 256 locations.

So you can't do it with one large two-dimensional const array.

Example:
This compiles OK:
Code:
const char array[2][128] =
{
{"ABCD"},
{"Hello"},
};


But this gives an error because 2 x 129 = 258, and that's greater than 256.
Code:
const char array[2][129] =
{
{"ABCD"},
{"Hello"},
};
LTS



Joined: 08 Dec 2005
Posts: 8

View user's profile Send private message

PostPosted: Wed Dec 21, 2005 3:20 pm     Reply with quote

Damn... I guess I could use several arrays, but then again I get an indexing problem. What is the best way to store several strings around 100 chars, and easily use an integer to reach the correct one?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 21, 2005 3:38 pm     Reply with quote

Here is one way. The code below displays this:
Quote:
ABCD
Hello World
The quick brown fox jumps over the lazy dogs back


Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

const char msg1[] ={"ABCD"};
const char msg2[] ={"Hello World"};
const char msg3[] ={"The quick brown fox jumps over the lazy dogs back"};

void display_msg(int8 index)
{
switch(index)
  {
   case 1:
      printf(msg1);
      break;

   case 2:
      printf(msg2);
      break;

   case 3:
      printf(msg3);
      break;

  }   

printf("\n\r");

}

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


display_msg(1);
display_msg(2);
display_msg(3);

while(1);
}
LTS



Joined: 08 Dec 2005
Posts: 8

View user's profile Send private message

PostPosted: Wed Dec 21, 2005 3:49 pm     Reply with quote

Yeah, that would work. Thanks!
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