LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-29-2008, 02:50 AM   #1
divya_flora
LQ Newbie
 
Registered: Jul 2008
Posts: 15

Rep: Reputation: 0
Structure in C


Hi Everyone....
I have a structure:
typedef struct
{
unsigned char command;
unsigned char data_length;
char data[MAX_DATA_LENGTH];
}PACKET;

My problem is that,I want to use a function here...
When i assign values to these variables they are as:
COMMAND,20,'S'...........
I want to call a function here..or assign a function value here........
as,
COMMAND,20,make().........

is it possible to do so...

Thanks ...
Divya
 
Old 09-29-2008, 03:46 AM   #2
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 492

Rep: Reputation: 50
Hi,
Yes it's possible, you have to use a pointer on function, something like

Code:
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;
   /* ... */
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Home Jail Folder Structure like Gobolinux Directory Structure luispt Linux - General 3 07-26-2008 07:46 PM
structure browser? jiml8 Programming 16 05-18-2008 05:48 PM
structure within a structure in C knobby67 Programming 3 03-06-2007 10:00 AM
structure os2 Programming 6 05-29-2005 08:39 PM
Forum Structure Lord-Rashid LQ Suggestions & Feedback 9 05-15-2004 11:31 AM


All times are GMT -5. The time now is 10:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration