I need help modifying this function. I need it to prompt the user for the file name and store it's contents in into the dynamic array. Instead of asking for the value from the user as it does. I have been working on this for hours with no luck. void FillArray(text*& ray, int& num_words) { char buffer[256] = ""; cout << "How many faculty do you want to enter: "; cin >> num_words; ray = new text[num_words]; for (int i = 0; i < num_words; ++i) { cout << "Please enter the Faculty's name: "; cin.ignore(cin.rdbuf()->in_avail()); cin.getline(buffer, 255); cin.clear(); cin.ignore(cin.rdbuf()->in_avail()); ray[i].word = new char[strlen(buffer) + 1]; strcpy(ray[i].word, buffer); cout << "Please enter the Faculty's department: "; cin.ignore(cin.rdbuf()->in_avail()); cin.getline(buffer, 255); cin.clear(); cin.ignore(cin.rdbuf()->in_avail()); ray[i].department = new char[strlen(buffer) + 1]; strcpy(ray[i].department, buffer); } }
I need help modifying this function. I need it to prompt the user for the file name and store it's contents in into the dynamic array. Instead of asking for the value from the user as it does. I have been working on this for hours with no luck.
void FillArray(text*& ray, int& num_words)
{
char buffer[256] = "";
cout << "How many faculty do you want to enter: ";
cin >> num_words;
ray = new text[num_words];
for (int i = 0; i < num_words; ++i)
{
cout << "Please enter the Faculty's name: ";
cin.ignore(cin.rdbuf()->in_avail());
cin.getline(buffer, 255);
cin.clear();
cin.ignore(cin.rdbuf()->in_avail());
ray[i].word = new char[strlen(buffer) + 1];
strcpy(ray[i].word, buffer);
cout << "Please enter the Faculty's department: ";
cin.ignore(cin.rdbuf()->in_avail());
cin.getline(buffer, 255);
cin.clear();
cin.ignore(cin.rdbuf()->in_avail());
ray[i].department = new char[strlen(buffer) + 1];
strcpy(ray[i].department, buffer);
}
}
Step by step
Solved in 2 steps with 1 images