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

Can I use Pointers in an Array?

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







Can I use Pointers in an Array?
PostPosted: Tue Jul 25, 2006 9:20 pm     Reply with quote

Hello, I'm trying to write 14 bytes to EEProm. The first function works correctly however I'm trying to reduce the code. I attempted a for loop with pointers in the second function. I don't have any experience wth pointers so I'm assuming I can't have an array of pointers. Can anyone suggest a way to do what I'm trying to do?

Code:

void WriteEEprom(){
   write_eeprom(5,MAKE8(Fqmax,0));
   write_eeprom(4,MAKE8(Fqmax,1));

   write_eeprom(9,MAKE8(Vmax,0));
   write_eeprom(8,MAKE8(Vmax,1));

   write_eeprom(13,MAKE8(Imax,0));
   write_eeprom(12,MAKE8(Imax,1));

   write_eeprom(17,MAKE8(kWmax,0));
   write_eeprom(16,MAKE8(kWmax,1));
   write_eeprom(15,MAKE8(kWmax,2));
   write_eeprom(14,MAKE8(kWmax,3));

   write_eeprom(25,MAKE8(HourMeter,0));
   write_eeprom(24,MAKE8(HourMeter,1));
   write_eeprom(23,MAKE8(HourMeter,2));
   write_eeprom(22,MAKE8(HourMeter,3));
}


Code:

void WriteEEprom(){
   int wEEaddr[14] = {5,4,9,8,13,12,17,16,15,14,25,24,23,22};
   int *wEEval[14] = {&Fqmax,&Fqmax+1,&Vmax,&Vmax+1,&Imax,&Imax+1,&kWmax,&kWmax+1,&kWmax+2,&kWmax+3,&HourMeter,&HourMeter+1,&HourMeter+2,&HourMeter+3};
   int i;
   for(i=0;i>14;i++){
   write_eeprom(wEEaddr[i],*wEEval[i]);
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 25, 2006 9:29 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=27405&start=5
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Wed Jul 26, 2006 6:24 am     Reply with quote

Note that CCS inlines the write_eeprom code. If you wrap the function inside another function you will save a ton of space.
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