-   Programming (
-   -   Structure in C (

divya_flora 09-29-2008 02:50 AM

Structure in C
Hi Everyone....
I have a structure:
typedef struct
unsigned char command;
unsigned char data_length;
char data[MAX_DATA_LENGTH];

My problem is that,I want to use a function here...
When i assign values to these variables they are as:
I want to call a function here..or assign a function value here........

is it possible to do so...

Thanks ...

jf.argentino 09-29-2008 03:46 AM

Yes it's possible, you have to use a pointer on function, something like


struct Packet {
    int (*do_command) (arg);
    unsigned char data_length;
    char data [MAX_DATA_LENGTH];

int my_command (arg) {
  /* Do what you want */

int main (void) {
  struct Packet packet;
  packet.do_command = my_command;
  /* ... */

All times are GMT -5. The time now is 05:44 PM.