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

array problem

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



Joined: 11 Jun 2005
Posts: 38

View user's profile Send private message

array problem
PostPosted: Sun Jan 14, 2007 4:46 am     Reply with quote

#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







PostPosted: Sun Jan 14, 2007 5:54 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 14, 2007 7:58 am     Reply with quote

THANKS Ttelmah .
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