Hi there,
I am rather new to C, and I am having a bit of trouble finding information on this thing that I want to do (damn google is good - but it's a shame that the creator of C didn't know about it when he named the language after a letter of the alphabet!)
Basically, I have a struct that looks like:
and I want to define a method to call on the diffuser object (sorry about this object oriented lingo, I realise that a struct isn't really an object...) that might look like:Code:typedef struct { constpart * electrons; double energy; double weight ; double potential; double kinetic; char dead; } diffuser;
is this possible?Code:void zeroEnergy(void) { potential = 0.0; kinetic = 0.0; energy = 0.0; }
I have been searching around for info, and it does seem like it's do-able. Unfortunately my C book doesn't cover unions, and all the websites I have encountered do lots of things with pre-processor directives (and if anyone could point me to a good book on that topic, and on properly structuring programs by properly allocating the various bits of code between header files and program files then I'd be most grateful) - but the websites give examples that are a little hard to follow and one even included a header that I don't have! (oocp.h or something)...
Any ideas?
many thanks in advance
James
*edit*
oh I should probably clarify - RE the title.
I called this post what I did because I thought it would mean people might understand what I wanted to achieve functionality-wise... i know that structs are not objects and so cannot have 'methods' (i guess)... but I figured people might see the functionality I wanted and tell me the C way of doing it... thanks!