Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble passing an array of structs
    text
    copied!<p>I cant for the life of me figure out how to pass this array of structs throughout my program. Could anyone lend a hand? Right now i am getting an error in main that says: expected primary expression before ')' token. </p> <p><strong>Header:</strong> </p> <pre><code>#ifndef HEADER_H_INCLUDED #define HEADER_H_INCLUDED #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;string&gt; #include &lt;cstring&gt; #include &lt;iomanip&gt; #include &lt;cctype&gt; using namespace std; struct addressType { char streetName[36]; char cityName[21]; char state[3]; char zipcode[6]; char phoneNumber[15]; }; struct contactType { char contactName[31]; char birthday[11]; addressType addressInfo; string typeOfentry; }; typedef struct contactType contactInfo; void extern readFile(ifstream&amp;, int&amp;, struct contactType *arrayOfStructs); void extern sortAlphabetically(); void extern userInput(char&amp;); void extern output(char&amp;); #endif // HEADER_H_INCLUDED </code></pre> <p><strong>main:</strong></p> <pre><code>#include "header.h" int main() { ifstream inFile; char response; int listLength; struct arrayOfStructs; inFile.open("AddressBook.txt"); if (!inFile) { cout &lt;&lt; "Cannot open the input file." &lt;&lt; endl; return 1; } readFile(inFile, listLength, arrayOfStructs); sortAlphabetically(); userInput(response); output(response); return 0; } </code></pre> <p><strong>readFile:</strong></p> <pre><code>#include "header.h" void readFile(ifstream&amp; inFile, int&amp; listLength, struct arrayOfStructs[]) { contactInfo arrayOfStructs[listLength]; char discard; inFile &gt;&gt; listLength; inFile.get(discard); for (int i = 0; i &lt; listLength; i++) { inFile.get(arrayOfStructs[i].contactName, 30); inFile.get(discard); inFile.get(arrayOfStructs[i].birthday, 11); inFile.get(discard); inFile.get(arrayOfStructs[i].addressInfo.streetName, 36); inFile.get(discard); inFile.get(arrayOfStructs[i].addressInfo.cityName, 21); inFile.get(discard); inFile.get(arrayOfStructs[i].addressInfo.state, 3); inFile.get(discard); inFile.get(arrayOfStructs[i].addressInfo.zipcode, 6); inFile.get(discard); inFile.get(arrayOfStructs[i].addressInfo.phoneNumber, 15); inFile.get(discard); inFile &gt;&gt; arrayOfStructs[i].typeOfentry; inFile.get(discard); } } </code></pre>
 

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