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

Copying by an array of pointers to const char[] doesn't work

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



Joined: 15 May 2009
Posts: 12

View user's profile Send private message

Copying by an array of pointers to const char[] doesn't work
PostPosted: Tue Jun 30, 2009 9:53 am     Reply with quote

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?
Ttelmah
Guest







PostPosted: Tue Jun 30, 2009 10:16 am     Reply with quote

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
kaz



Joined: 15 May 2009
Posts: 12

View user's profile Send private message

PostPosted: Tue Jun 30, 2009 10:48 am     Reply with quote

Nuts. I thought it was the same problem. I'll try the 2-dimensional array then.

Thanks for the information.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 30, 2009 11:47 am     Reply with quote

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:
Quote:
Hey, you.


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);
}
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