Note that there are some explanatory texts on larger screens.

plurals
  1. POFor loops and inputing data?
    primarykey
    data
    text
    <p>trying to figure out how to make a little inventory program and I can't for the life figure out why it isn't working.</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;string&gt; using namespace std; struct record { int item_id; string item_type; int item_price; int num_stock; string item_title; string item_author; int year_published; }; void read_all_records(record records[]); const int max_array = 100; int main() { record records[max_array]; read_all_records(records); cout &lt;&lt; records[2].item_author; return 0; } void read_all_records(record records[]) { ifstream invfile; invfile.open("inventory.dat"); int slot = 0; for (int count = 0; count&lt;max_array; count++); { invfile &gt;&gt; records[slot].item_id &gt;&gt; records[slot].item_type &gt;&gt; records[slot].item_price &gt;&gt; records[slot].num_stock &gt;&gt; records[slot].item_title &gt;&gt; records[slot].item_author &gt;&gt; records[slot].year_published; slot++; } invfile.close(); } </code></pre> <p>I'm testing it by having it print the second item from records author. When I run it, it doesn't show the authors name at all. The .dat file is located in just about every folder where the project is (I forgot which folder it needs to be in) so it's there. The issue isn't that the file isn't working. It's the array not printing off anything. my inv file is basically:</p> <p>123456 book 69.99 16 title etc etc</p> <p>and repeats for different books/cds etc all on one line, all without spaces. Should just next in.</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.
    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