View previous topic :: View next topic |
Author |
Message |
Georg Prinz
Joined: 07 Jan 2004 Posts: 22 Location: Frankfurt, Germany
|
Passing string with variable length to function |
Posted: Mon Mar 07, 2005 3:38 pm |
|
|
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('').
Thank you for for help in advance.
Saludos
Jorge
_________________ dl 2 kp |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 07, 2005 3:53 pm |
|
|
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
|
Variable string to function |
Posted: Tue Mar 08, 2005 3:05 am |
|
|
javascript:emoticon('')
Rolling Eyes
What a pity!
Gracias for the quick answer.
Saludos
Jorge _________________ dl 2 kp |
|
|
|