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

Passing string with variable length to function

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



Joined: 07 Jan 2004
Posts: 22
Location: Frankfurt, Germany

View user's profile Send private message Send e-mail

Passing string with variable length to function
PostPosted: Mon Mar 07, 2005 3:38 pm     Reply with quote

Hi folks,
does anybody have an idea why following code cannot pass a string to a function (i use PCW 3.212 and a 18Pic252 chip):

void LCDstr(char *strptr)
{
char pi, ch, punto[22];

pi = 0;
for(pi=0;strptr[pi];pi++) punto[pi]=strptr[pi]);
.......
}

......

void main(void)
{
.......

LCDstr("Hi CCS Forum");

......
}

The array punto[pi] receives garbage only!!!javascript:emoticon('Evil or Very Mad').

Thank you for for help in advance.

Saludos

Jorge



Evil or Very Mad
_________________
dl 2 kp
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 07, 2005 3:53 pm     Reply with quote

The CCS compiler can't use pointers to strings in ROM.
To get a pointer to the string, you have to copy it into
a RAM buffer, and then use the pointer to the RAM buffer.
See the changes to your program, shown in bold below:

char string[50];
void main(void)
{


strcpy(string, "Hi CCS Forum");
LCDstr(string);

......
}
Georg Prinz



Joined: 07 Jan 2004
Posts: 22
Location: Frankfurt, Germany

View user's profile Send private message Send e-mail

Variable string to function
PostPosted: Tue Mar 08, 2005 3:05 am     Reply with quote

javascript:emoticon('Rolling Eyes')
Rolling Eyes
What a pity!
Gracias for the quick answer.

Saludos

Jorge
_________________
dl 2 kp
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