View previous topic :: View next topic |
Author |
Message |
iw2nzm
Joined: 23 Feb 2007 Posts: 55
|
strcpy and write_eeprom |
Posted: Thu Oct 11, 2007 8:50 am |
|
|
Hi,
please consider this short code:
Code: |
char *sPassword[9];
void main() {
int8 i;
...
strcpy(sPassword, "0000");
for (i = 0; i < 8; i++) write_eeprom(12 + i, sPassword[i]);
for (;;) {}
}
|
After programmed with ICD2 and ran, I expect to see in the eeprom something like this:
0x0C -> 0x30 // '0'
0x0D -> 0x30 // '0'
0x0E -> 0x30 // '0'
0x0F -> 0x30 // '0'
0x10 -> 0x00 // '\0'
0x11 -> ???
0x12 -> ???
0x13 -> ???
Where ??? means not significative data.
Insted I read:
0x0C -> 0x30 // '0'
0x0D -> 0x30 // '0'
0x0E -> 0x00 // '0'
0x0F -> ???
0x10 -> ???
0x11 -> ???
0x12 -> ???
0x13 -> ???
Do you know why?
I'm using a PIC18F4520 and CCS PCH 4.025.
Marco / iw2nzm |
|
|
Ttelmah Guest
|
|
Posted: Thu Oct 11, 2007 9:02 am |
|
|
Your declaration of sPassword, says that this is a pointer to an array. An _array_ declaration, is already a pointer to the data. Get rid of the leading '*' on the declaration.
Best Wishes |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Oct 11, 2007 9:20 am |
|
|
Actually isn't it an array of char pointers!
A pointer to an array would be
char array[10];
char *p = array;
Where as
char *p[10];
Is an array of 10 char pointers, ie
char array[10][10];
p[0] = array[0];
p[1] = array[1];
*p[0] = array[0][0];
etc... |
|
|
iw2nzm
Joined: 23 Feb 2007 Posts: 55
|
|
Posted: Thu Oct 11, 2007 9:21 am |
|
|
Well, let me say I'm too tired to code today... It's better I stop and go out for a walk...
Thanks for the quick answer!
Marco / iw2nzm |
|
|
|