title: C++ Arrays and Reading from file
body: <p>I'm creating an address book program that allow user to search by first name, last name,phone number and address. The user is prompted to enter a file name and the file is read into  an array. I'm having trouble modifying by existing SearchFirstName function to loop through array. I have read over this topic multiple times I'm just not understanding it. Any help would be greatly appreciated. </p>
  
  <p>File</p>
  
  <pre><code>Susan, Smith, 123 456 789 
  101 Main Street
  Bob, Smith, 567 345 9076 
  456 Market Street
  </code></pre>
  
  <p>Header File</p>
  
  <pre><code>#include&lt;string&gt;
  using namespace std;
  
  enum Title {Mr, Mrs, Ms, Dr, NA};
  
  struct NameType {
  Title title;
  string firstName;
  string lastName;
  };
  
  struct AddressType {
    string street;
    string city;
    string state;
    string zip;
  };
  
  struct PhoneType {
    int areaCode;
    int prefix;
    int number;
  };
  
    struct entryType {
    NameType name;
    AddressType address;
    PhoneType phone;
  };
  
  const int MAX_RECORDS = 50;
  
   struct addressBookType {
     entryType record[MAX_RECORDS];
     int numEntries;
  };
  </code></pre>
  
  <p>Code</p>
  
  <pre><code>string bookArray[MAX_RECORDS];
  
  int main()
  {
     entryType userRecord;
     string filename;
     ifstream inData;
     char searchOption;
  
     OpenFile(filename, inData);
  
     MainMenu(inData, filename);
  
     return 0;
  }
  
  void OpenFile(string&amp; filename, ifstream&amp; inData)
  {
      do {
         cout &lt;&lt; "Enter file name to open: ";
         cin &gt;&gt; filename;
  
        inData.open(filename.c_str());
  
      if (!inData)
          cout &lt;&lt; "File not found!" &lt;&lt; endl;
  
  } while (!inData);
  
  
    if(inData.is_open())
    {
  
         for(int i=0; i&lt;MAX_RECORDS;i++)
         {
           inData&gt;&gt; bookArray[i];
         }
     }
  }
  
  // Searches passed file stream for a first name read from the user
  
   void SearchFirstName(ifstream&amp; inData)
  {
    string searchName;
    entryType userRecord;
    string normalSearchName, normalFirstName;
    char choice;
    bool found = false;
  
    cout &lt;&lt; "Enter first name to search for: ";
    cin &gt;&gt; searchName;
  
    normalSearchName = NormalizeString(searchName);     // Convert name to all uppercase
  
    // Loop through all records in the file
    while (GetRecord(inData, userRecord)){
  
      normalFirstName = NormalizeString(userRecord.name.firstName);   // Convert retrieved string to all uppercase
  
      if (normalFirstName == normalSearchName) { // Requested name matches
          PrintRecord(userRecord);
          cout &lt;&lt; "Is this the correct entry? (Y/N)";
          cin &gt;&gt; choice;
          choice = toupper(choice);
          cout &lt;&lt; endl;
  
          if (choice == 'Y') {
              found = true;
              break;
          }
      }
  }
  
  // Matching name was found before the end of the file
  if (inData &amp;&amp; !found){
      cout &lt;&lt; "Record found: " &lt;&lt; endl;
      PrintRecord(userRecord);
      cout &lt;&lt; endl;
  }
  else if (!found)   // End of file. Name not found.
  {
      cout &lt;&lt; searchName &lt;&lt; " not found!" &lt;&lt; endl &lt;&lt; endl;
  }
  
  // Clear file fail state and return to beginning
  inData.clear();
  inData.seekg(0);
  }
  </code></pre>
  
  <p>My attempt</p>
  
  <pre><code>void SearchFirstName(ifstream&amp; inData)
  {
     string searchName;
     entryType userRecord;
  
  
  cout &lt;&lt; "Enter first name to search for: ";
  cin &gt;&gt; searchName;
  
  string newSearchName = NormalizeString(searchName);
  string upFirst = NormalizeString(userRecord.name.firstName);
  
  for (int i=0;i&lt;MAX_RECORDS;i++)
  {
      while(newSearchName == upFirst)
      {
          if (bookArray[i]== upFirst)
          {
              cout&lt;&lt;"Name Found";
              cout &lt;&lt;bookArray[i]; //test case
          }
      }
  
  
  }
  }
  </code></pre>