Hi Marquinho,
I changed your code so it does what you would like.
The problem, as someone already said, is that if in your code you write:
route[0] = "This lines";
route[0] points to somewhere in flash memory where there is the string "burned" on flash.
After you try to change the single charachters, but you try to change a flash cell as if it was a RAM cell, you can't.
With my code, strings are initialized and put in RAM.
Before each "for loop" , I made route[?] point to RAM, so I can write something on it.
Of course, you waste precious RAM cells to store strings.
Hope it helps.
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
char string0[]= "This lines";
char string1[]= "work";
char string2[]= "fine if I";
char string3[]= "assign them";
char string4[]= "directly";
char *route[5] = {string0, string1, string2, string3, string4};
char *y;
char x[5];
char c, index;
void main(void) {
EnableInterrupts; /* enable interrupts */
/* include your code here */
// EnableInterrupts; /* enable interrupts */
//SOPT_COPE = 0;
/*
route[0] = "This lines";
route[1] = "work";
route[2] = "fine if I";
route[3] = "assign them";
route[4] = "directly";
*/
for (c = 0 ; c < 5 ; c++)
{
route[c] = "message";
}
route[1] = string1;
y= "FREE";
for (index = 0 ; index < 4; index ++)
{
(route[1])[index] = y[index]; // No change
x [index] = y[index];
}
x[index] = '\0';
route[2] = string2;
y= "free";
for (index = 0 ; index < 4; index ++)
{
*(route[2] + index) = y[index]; // No change
*(x + index) = y[index];
}
x[index] = '\0';
route[3] = string3;
y= "scal";
for (index = 0 ; index < 4; index ++)
{
*(route[3] + index) = *(y + index); // No change
*(x + index) = *(y + index);
}
x[index] = '\0';
for(;;) {
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
Message Edited by BV_BV on 2009-04-04 08:05 AM
Message Edited by BV_BV on 2009-04-04 08:08 AM