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

Preform an action on a string

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



Joined: 21 Jan 2010
Posts: 13

View user's profile Send private message

Preform an action on a string
PostPosted: Thu Jan 21, 2010 6:25 am     Reply with quote

16F628A
PCM 4.057

Hi,

I try to kind of port a AVR GCC pice of code to CCS but i can't get it to work.

The pice of GCC code:
Code:
void display_str(char *s) {
   uint8_t i;

   // don't use the lefthand dot/slash digit
   display[0] = 0;

   // up to 8 characters
   for (i=1; i<9; i++) {
   // check for null-termination
      if (s[i-1] == 0)
         return;

      // Numbers and leters are looked up in the font table!
      if ((s[i-1] >= 'a') && (s[i-1] <= 'z')) {
         display[i] =  pgm_read_byte(alphatable_p + s[i-1] - 'a');
      }
      else if ((s[i-1] >= '0') && (s[i-1] <= '9')) {
         display[i] =  pgm_read_byte(numbertable_p + s[i-1] - '0');
      } else {
         display[i] = 0;      // spaces and other stuff are ignored :(
      }
   }
}


After that it's called like:
display_str("text")

Where in CCS I ported the functions
pgm_read_byte(alphatable_p + var - 'a') -> alpha(var)
pgm_read_byte(numbertable_p + s[i-1] - '0') -> number(var)

It has to perform a action on every char in a string, max 8 char + terminator, and store it in an array starting @ [1] every time the function is called.

But it does not work. I end up with "Attempt to create a pointer to a constant" I can understand that part because of CCS makes the piece of text a const.

So i tried to call it like:
char test[9];
test = "text";
printStr(test);
But line 2 gives 'Expecting LVALUE such as a variable name or * expression"

So i'm kind of lost how to make this work in CCS. Mayby i don't think the right way but i can't get around it. I hope someone can help.
Ttelmah
Guest







PostPosted: Thu Jan 21, 2010 9:06 am     Reply with quote

You can't transfer a string, using '='. This is standard in C. Look at 'strcpy'.
If you look at the first example, this shows exactly how to do what you want... Smile

Best Wishes
Guest








PostPosted: Sat Jan 23, 2010 1:01 pm     Reply with quote

Thnx! I get it to work now. Forgot about strings. I kept the function but call it like:
Code:

txtarray[10];

....

strcpy(txtarray, "message");
display_str(txtarray);


And to make it less code make a define
Code:

#DEFINE printStr(var)   strcpy(txtarray, var); display_str(txtarray);

All I need to do is call
printStr("message")

Or is there a better way so I can call just one function like
printStr("message") ?
septillion



Joined: 21 Jan 2010
Posts: 13

View user's profile Send private message

PostPosted: Sat Jan 23, 2010 1:02 pm     Reply with quote

That was me, not knowing I was posting as a guest...
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