Note that there are some explanatory texts on larger screens.

plurals
  1. POC return array pointers from two different c files for use in a function with no global's allowed
    primarykey
    data
    text
    <p>I am writing a C assignment for one of my university modules. I am trying to return pointers to two arrays (1 array from each c file) for use in a function in a different c file. I will then do the correct calculations on said arrays.</p> <p>The current problem i am facing:</p> <p><strong>Note: the code below has has been simplified to be more readable the main elements are still in place</strong> </p> <ol> <li>The assignment restricts the use of global variables</li> <li>one array is in a file mayday.c</li> <li>one array is in a file ships.c</li> <li>the function call is in a file system_handler.c</li> </ol> <p> I need to be able to return the arrays from 2 and 3, for use in function in 4.</p> <p>the code is:</p> <p>mayday.c</p> <pre><code>#include &lt;stdio.h&gt; #include "mayday.h" #include "rescue_assets.h" #include "ship.h" void assign_mayday_to_ships() { mayday_call* m_ptr; ship* sh_ptr; /*correct operations on the arrays */ } </code></pre> <p>ships.c</p> <pre><code> void read_ship_locations() { ship ships[10]; /* fill array methods removed */ ret_ship_array(ships); } ship* ret_ship_array(ship ships[]) { return ships; } </code></pre> <p>The function call i am trying to use the two array's with:</p> <pre><code>#include &lt;stdio.h&gt; #include "mayday.h" #include "rescue_assets.h" #include "ship.h" void assign_mayday_to_ships() { mayday_call* m_ptr; ship* sh_ptr; /*correct operations on the arrays */ } </code></pre> <p>The assign_mayday_to_ships will use pointers which will be results on the return array methods from mayday.c and ship.c but i am unsure how to implement this.</p> <p>Any advice will be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload