Ok this code outputs a name, but i cant figure out how to output the array in my function, from the main( ).
I know the code in my getInfo function works, and if i output the information inside the function it works, however how do i output it from inside the main( ).
code in blue is where i try to output the marks[j], tried a few things to no avail.Code:#include <iostream> #include <string> #include <fstream> using namespace std; bool getInputFilename(char fname[]) { ifstream fin; cout << "Please enter the filename for input : "; cin >> fname; fstream fs(fname, ios_base::in); if (!fs) { return false; } else { fin.close(); return true; } } bool getOutputFilename(char fname[]) { ofstream fout; cout << "Please enter the filename for output : "; cin >> fname; fout.open(fname); if (fout.fail()) return false; fout.close(); return true; } void getInfo(ifstream& fin, ofstream& fout, int marks[], char name[]) { fin.getline(name, 100, '\n'); for(int j=0; j<12; j++) { fin >> marks[j]; } } void main() { ifstream fin; ofstream fout; char name[100]; int marks[12]; char IFname[20], OFname[20]; while (!getInputFilename(IFname)) { cout << "Invalid filename try again!\n\n"; } while (!getOutputFilename(OFname)) { cout << "Invalid filename try again!\n\n"; } fout.open(OFname); fin.open(IFname); getInfo(fin, fout, marks, name); fout << name << endl; fout << marks << endl; fout.close(); fin.close(); }



LinkBack URL
About LinkBacks



CornedBee