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 support@ccsinfo.com

Pass constant string to function

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







Pass constant string to function
PostPosted: Fri Jul 18, 2003 3:23 am     Reply with quote

I would like to pass a constant string to a function e.g.

TXT_EEPR(int EEPRStart, char * TXT)
{
int TXTi;
for(TXTi=0; TXTi }

void Main()
{
TXT_EEPR(100, "Text to write to EEPROM");
}

I get compiler error: "Bad expression syntax"

I managed to do it by first sprintf the constant string to an array, but this is too expensive on ROM.

Can someone please assist me to do this effectively.

Thank you

Levett
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516133
R.J.Hamlett
Guest







Re: Pass constant string to function
PostPosted: Fri Jul 18, 2003 5:51 am     Reply with quote

:=I would like to pass a constant string to a function e.g.
:=
:=TXT_EEPR(int EEPRStart, char * TXT)
:={
:=int TXTi;
:=for(TXTi=0; TXTi :=}
:=
:=void Main()
:={
:=TXT_EEPR(100, "Text to write to EEPROM");
:=}
:=
:=I get compiler error: "Bad expression syntax"
:=
:=I managed to do it by first sprintf the constant string to an array, but this is too expensive on ROM.
:=
:=Can someone please assist me to do this effectively.
:=
:=Thank you
:=
:=Levett
Basically, you can't.
The CCS compiler does not allow pointers to strings. However it does allow such strings to be addressed as arrays, or by a 'trick' shortcut.

int TXTi;

#define Reset_Ctr() TXTi=0;

TXT_EEPR(int EEPRStart, char TXT)
{
write_eeprom((EEPRStart+TXTi), TXT);
}

//Then if you want to start at '0' in the EEPROM, call:

Reset_Ctr();
TXT_EEPR(100, "Text to write to EEPROM");

This shortcut, calls the function once for each character in the message string, which will transfer the data as required. Since it does not though know when you have finished, you have to 'reset the counter' seperately.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516134
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