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

defining length of array

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dave the blade
Guest







defining length of array
PostPosted: Wed Nov 02, 2005 4:57 am     Reply with quote

Hi gents and ladies, ver 3.234, is there a way to define the length of an array to capture a_to_d readings after compilation of the program, in other words by entering a value from a keypad that tells the program the length of the array.
Cheers dave
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Wed Nov 02, 2005 7:08 am     Reply with quote

I never tried it in the PIC environment, but i'll try to explain it the way i understand it to work:

Arrays are defined during compile-time, so you can't really define the length on-the-fly.

I think the solution you'd be looking for is to define a pointer to a char:

char *my_ptr;

Then you do a malloc() for the length you want.

e.g.
my_ptr = malloc(...);

After that, then you can address the contents accordingly via:
my_ptr[x] = 0x20; // for example
or
*(my_ptr + x) = 0x20;

I think the two statements above are equal, but I am not sure if CCS supports both.

OR

The easiest would be to just define an array of your worst-case longest length.
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