![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Levett Prins Guest
|
Pass constant string to function |
Posted: Fri Jul 18, 2003 3:23 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
R.J.Hamlett Guest
|
Re: Pass constant string to function |
Posted: Fri Jul 18, 2003 5:51 am |
|
|
:=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 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|