Edit prototype and declarations of functions

This is the structure of the program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 void open (void);
 void insert (void);
 void search (void);
 void update (void);
 void delete (void);
 void display (void);
 void save (void);

 struct comp
 {
     int code;
     char name [27];
     des char [52];
     int avail;
     struct comp * n;
 };

 struct comp * comps = 0;

 void (* cmd []) (void) = {open, insert, search, update, delete, display, save};

 int main ()
 {
 int c;

 for (;;)
 {
 scanf ("%i", &c);
 (*cmd[c ])();
 }
 }
 




How do I edit prototype and declarations of functions and the vector of function pointers to declare comps in the main function and pass it as a parameter to all the other functions?
I am not able to understand you .. can you make me more clear ,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

void open (void)
{
    //your code . 
}
 void insert (void)
{
    //your code 
}
 void search (void)
{
     //bla bla bla 
}
 void update (void)
{
   //bla bla 
}
 void delete (void)
{ 
       //bla bla
}
 void display (void)
{
        //bla bla 
}
 void save (void)
{
    /bla bla 
}
Last edited on
Is this what you want?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
struct comp;

void open (struct comp*);
void insert (struct comp*);
void search (struct comp*);
void update (struct comp*);
void delete (struct comp*);
void display (struct comp*);
void save (struct comp*);

struct comp
{
  int code;
  char name [27];
  des char [52];
  int avail;
  struct comp * n;
};

struct comp * comps = 0;
void (* cmd []) (struct comp*) = {
  open, insert, search, update, delete, display, save
};

int main ()
{
  int c;
  comps = malloc(sizeof(struct comp));
  for (;;)
    {
      scanf ("%i", &c);
      (*cmd[c ])(comps);
    }
}

Last edited on
Topic archived. No new replies allowed.