Note that there are some explanatory texts on larger screens.

plurals
  1. POC pass size of an array to another c file variable
    primarykey
    data
    text
    <p>This question is probably a really simple fix but i have come fresh from a Java background so i find C a tiny bit confusing at times so bare with me please.</p> <p>*<em>Issue overview *</em></p> <p>The current issue i have is that i have an array which has the size of a variable which happens to be the amount of lines in a file. This is an integer which is calculated and returned, which becomes the arraysize (e.g. file text.txt has 12 lines so the array is of size 12).</p> <p>I want to know how i can return this value to another c file for use in a function so i can loop through the complete array.</p> <p><strong>points to note</strong></p> <ol> <li>I am not allowed any globals at all in this assignment, no global arrays/variables at all.</li> <li>The line counting functions works correctly so i will not be posting it here</li> <li>The array is set up correctly and print the correct results</li> <li>Most of the code from the functions has been removed to make it easier to read.</li> <li>The correct #includes for each file are present, i just need an example of how to do it.</li> </ol> <p>The code:</p> <pre><code>void read_from_file() { /* reading and parsing removed */ no_of_lines = (count_lines(locof) - 1); /* locof is a char array storing the file name */ ship ships[no_of_lines]; /* i want to return the value of no_of_lines *? </code></pre> <p><strong>I want to return the value of no_of_lines</strong></p> <p>The c file where i need the value</p> <pre><code> /*This is where i need the variable */ void asign_mayday_to_ships() { int* ship_arr_length = SIZE OF SHIP ARRAY NEEDED mayday_call* mday_ptr; ship* ship_ptr; /* this is a ship array */ mday_ptr = read_mayday_file(); ship_ptr = read_ship_locations(); int i; for(i = 0; i &lt; SIZE OF SHIP ARRAY; i++){ } </code></pre>
    singulars
    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.
    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