This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
In my main:
#include <iostream>
include <fstream>
include <string>
using namespace std;
struct Employee { string name; int nKeysPossessed; string keys[5]; };
bool reader(string input_filename, Employee employees[], int& nEmployees) { Â Â /This function should take a string for the filename, Â Â an array of Employee array, and the number of employees (should be passed in as reference) as input./ int keyNum = 0;
string enter;
string names;
string key;
ifstream ifs;
ifs.open(input_filename);
if(!ifs.is_open()) Â Â { return false; Â Â }
getline(ifs, enter);
int count = stoi(enter);
nEmployees = count;
for(int i = 0; i < nEmployees; i ) Â Â { getline(ifs, names);
ifs >> keyNum;
ifs.ignore();
getline(ifs, key);
string finder = " "; string arr[keyNum]; int end = key.find(finder); int count = 0; int start = 0; string j;
for(int j = 0; j < keyNum; j ) Â Â Â Â { arr[j] = key.substr(start, end - start); start = end finder.size(); end = key.find(finder, start); cout << arr[j] << endl; cout << key << endl; Â Â Â Â } employees[i].keys[0] = "Yes"; cout << employees[i].keys[0] << endl; cout << keyNum << endl;
while(count < keyNum) Â Â Â Â Â Â { employees[i].keys[count] = arr[count]; Â Â Â Â Â Â }
cout << endl;
employees[i].name = names; employees[i].nKeysPossessed = keyNum;
  }
return true; }
int main() {
cout << "Please enter key file name to start: " << endl;
int nEmployees = 0;
string inputFile; cin >> inputFile;
string number; int size;
ifstream findEmployee; findEmployee.open(inputFile);
getline(findEmployee, number);
size = stoi(number);
Employee employees[nEmployees];
bool readerDetermine = reader(inputFile, employees, nEmployees);
if(readerDetermine == true) Â Â { cout << "it is working so far" << endl; Â Â }
if(readerDetermine == false) Â Â { cout << "Something wrong chief" << endl; Â Â }
return 0;
}
With an input file of this:
2
Ya Hoo
3 AHC102 AHC200 AHC111
Michael Lee
3 AHC303 AHC200 AHC324
I keep on trying to work it out, and every time I try to fill up the structure array, it comes out poorly. I was wondering if anyone could help me out, this is the only thing I need to REALLY get started on this program (I hope).
Subreddit
Post Details
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/cpp_questio...