![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
kaz
Joined: 15 May 2009 Posts: 12
|
Copying by an array of pointers to const char[] doesn't work |
Posted: Tue Jun 30, 2009 9:53 am |
|
|
I think it's broken, and I'd greatly enjoy this over the alternative switch statement:
Compiler version: 4.095
Chip: PIC16F886
Code: |
/*---Code example---*/
#include <stdio.h>
char *Greetings[] =
{ "Hello there.",
"Howdy.",
"Hey, you.",
"*mumble mumble*"
};
int main()
{ int delay = 0;
char lcd_buffer[16];
strcpy(lcd_buffer, Greetings[2]);
delay++; //At this point, lcd_buffer is filled with trash.
return 0;
}
|
I have this problem where this code compiles, but doesn't work. I tried it with a PC on gcc the other day with flying colors, not so much here. Is there a good reason for this, or another way to do it that's not a switch statement? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Tue Jun 30, 2009 10:16 am |
|
|
Do a search on the forum, for 'pointer to constant', or look in the manual....
You can get the required effect, by simply declaring a two dimensional text array, and copying the characters from the required line, into a string as needed.
The latter compilers, do have the ability to handle this using other compilation options (ANSI), _but_ at a large cost in terms of the actual time/code size needed to support this, and only on chips that support direct reading of the code memory. The problem is that the PIC itself has an unusual memory architecture, with the 'code' memory, not directly accessible to read/write, and on some chips not available at all....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
kaz
Joined: 15 May 2009 Posts: 12
|
|
Posted: Tue Jun 30, 2009 10:48 am |
|
|
Nuts. I thought it was the same problem. I'll try the 2-dimensional array then.
Thanks for the information. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 30, 2009 11:47 am |
|
|
Quote: | Compiler version: 4.095
Chip: PIC16F886 |
The latest version is 4.093, as far as I know. See the CCS versions page:
http://www.ccsinfo.com/devices.php?page=versioninfo
Quote: | I have this problem where this code compiles, but doesn't work. |
I was able to make it work by putting in numbers for the size of the
2-dimensional array. Here's the output:
Here's the program. This was tested with vs. 4.093.
Code: | #include <16F886.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
char Greetings[4][16] =
{ "Hello there.",
"Howdy.",
"Hey, you.",
"*mumble mumble*"
};
//================================
void main()
{
int delay = 0;
char lcd_buffer[16];
strcpy(lcd_buffer, Greetings[2]);
printf(lcd_buffer);
while(1);
} |
|
|
![](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
|