c - Passing struct pointer as a parameter -


I am trying to compile this code in c. First of all I have to use this structure in a different source file such as a "square" (dir.h)

  // structure typedef struct s_dirobject {int noteid; Four titles [20]; Int bytes; Four major [20]; Bool is_dir; Struct s_dirobject * Next; } Derobags; // Ops Zero add_dirobject (dirobject * myDirobject, int num_dirobject, four title [20], int is_dir, int bytes, char head [20]); Int get_dirobject_noteid (dirobject * myDirobject, int num_note); Char * get_dirobject_title (dirobject * myDirobject, int num_note); Int get_dirobject_bytes (dirobject * myDirobject, int num_note); Char * get_dirobject_head (dirobject * myDirobject, int num_note); Bull isdir (dirobject * myDirobject, int num_note); Int get_dirobjects_len (dirobject * myDirobject); Zero clear_dir (dirobject * myDirobject); Zero init_dir (dirobject * myDirobject);  

In the second place, I have a commy source for recovering the contents of a directory from a remote file system, and fill the object (comms.c)

 < Code> #include "notebook.h" #include "dir.h" dirobject * temporaldirobjects; ... init_dir (temporaldirobjects); Add items retrieved while (cond) {// directory add_dirobject (temporaldirobjects, index, title, is_dir, bytes, ""); } // When the content is retrieved from the source, then I request the notebook_windows notebook_init (source, path, temperedordabobases);  

Finally, my notebook window interface will look like this. (Notebook .h)

  #include "dir.h" zero notebook_init (char * source, char * path, dirobject * content); Zero notebook_danit ();  

and its implementation (notebook.c)

  zero notebook_init (four * source, four * path, dirobject * content) {// fill this_window_source = Source; This_window_path = path; This_window_dirobjects = content; ...}  

When I compile this code, I get an error saying that

  ../ src / dir.h : 13: 16: Error: 'struct s_dirobject' is included in the redefined file ../src/notebook.h12:02, from ../src/comms.c:25: ../src/dir.h: 13: 16: Note: Originally contained in the file defined here ../src/comms.c:27:02 is included: ../src/dir.h:20:3: Error: Disputed type for 'dirobject'. /src/notebook.h12:02, from ../src/comms.c:25: ../src/dir.h:20:3: Note: The previous announcement of 'debobject' was here in the file ../ Src / comms.c: 27: 02: ../src/dir.h:23:6: Error: for 'add_dirobject' Raspar Anti Type file contains ./src/notebook.h12: 0, from ../src/comms.c:25: ../src/dir.h:23:6: Note: 'add_rirbies' The previous announcement was here ...  

Since the comics library contains DIRH and Notebook H, and Notebook H does this too. And if I remove the included in the notebook, I get another error:

  included in the file ./src/comms.c:25:02: ../src/notebook H: 14: 46: Error: unknown type name 'debobject'  

How can I get it? I want to keep it as a clean code as I can.

You have included two headers in the file Comms.c

dir>
  #include "notebook.h" #include "dir.h"  

header notebook.h .h

  #include "dir.h" contains zero notebook_init (char * source, char * path, dirobject * content); Zero notebook_danit ();  

As a result the structure is defined twice in the same compilation unit. You must provide that each header will be included only once in each compilation unit. To do this, you have to supply the header quadrilateral for example

  #ifndef DIR_H #define DIR_H // structure typedef struct s_dirobject {int noteid; Four titles [20]; Int bytes; Four major [20]; Bool is_dir; Struct s_dirobject * Next; } Derobags; // ... #endif  

Or if the compiler supports #pragme once, then you can use it.


Comments