|
|
View previous topic :: View next topic |
Author |
Message |
ferrarilib
Joined: 11 Jun 2005 Posts: 38
|
array problem |
Posted: Sun Jan 14, 2007 4:46 am |
|
|
#rom 0x2100 = {0x4F, 0x4B, 0x00, 0x42, 0x55, 0x53, 0x59, 0x00}
..........
char* Read_E(long int EX)
{
char* buffer; // this do problem
//char buffer[10]; // this is good
int count;
int index_ex;
index_ex = EX;
count = 0;
do {
buffer[count] = read_EEPROM(index_ex++);
}while(buffer[count++] != 0x00);
return (buffer);
}
main()
{
printf(lcd_putc,"\f%s",Read_E(0));
while(1);
}
this is my problem.
if i do char *buffer the printf return samething not good, but if i do char buffer[10] return OK
where i do samething not good ?
thanks |
|
|
Ttelmah Guest
|
|
Posted: Sun Jan 14, 2007 5:54 am |
|
|
The problem here is, 'where is the buffer'...
The declaration:
char* buffer;
Means declare 'buffer', to be a pointer to a memory area. It does not assign any actual memory to _hold_ the data (except the pointer itself).
You then go and write data to the address referenced by this pointer, which can be anywhere in memory - no wonder it does not work....
If you did this on a processor that had a memory management chip (like a PC), you would get an exception error raised as soon as you tried to do this, that the program was attempting to access memory it shouldn't. Without this hardware protetion on the PIC, all you will get is data being destroyed...
You need to make a call to 'malloc' (with stdlibm loaded) to actually allocate some memory for 'buffer' to address.
Best Wishes |
|
|
ferrarilib
Joined: 11 Jun 2005 Posts: 38
|
|
Posted: Sun Jan 14, 2007 7:58 am |
|
|
THANKS Ttelmah . |
|
|
|
|
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
|