All I want to do is pass my array "p" which is a 2-dimensional string array to the function changeData()... . Can't remember how to pass that. Any ideas?
Code:
#include <iostream> #include <string> #include <fstream> #include <new> #include <iomanip> using namespace std; /* function: countRecords params: string fileName, bool outputTF purpose: counts records from passed file name and outputs data if bool is true */ int countRecords(string fileName, bool outputTF) { ifstream inFile; int recordCount = 0; inFile.open(fileName.c_str(),ios::in); if(inFile.is_open()) { //priming read inFile.ignore(1000,'\n'); recordCount = 1; //loop while(!inFile.eof()) { inFile.ignore(1000,'\n'); recordCount++; } if(outputTF == true) { cout << "recordCount= " << recordCount << endl; } }else{ cout << "File would not open!" << endl; } inFile.close(); return recordCount; } void listData(string arr) { cout.setf(ios::left); cout << setw(5) << "#" << setw(5) << "ID" << setw(50) << "DESC" << setw(8) << "COST" << setw(6) << "SUPPLY" << endl; cout << endl; } void changeData(string arr) { listData(arr); system("pause"); } int printMenu() { int option = 0; cout << endl; cout << " 1 Change Data" << endl; cout << " 0 Exit" << endl; cout << "Type number from left to choose operation: "; cin >> option; return option; } // ***************** MAIN PROCEDURE *********************** int main() { string fileName = "data1.dat"; int c = countRecords(fileName,false);//one hundred million records MAX string **p = new string * [c]; for(int i=0; i<c; i++) { p[i] = new string [4]; } ifstream inFile; inFile.open("data1.dat",ios::in); if(inFile.is_open()) { while(!inFile.eof()) { for(int i=0; i<c; i++) { for(int t=0; t<4; t++) { if(t==3) { getline(inFile,p[i][t],'\n'); //cout << t << ": " << p[i][t] << endl; //system("pause"); }else{ getline(inFile,p[i][t],'_'); //cout << t << ": " << p[i][t] << endl; //system("pause"); } }//end for t }//end for i }//end while !eof int option = printMenu(); while(option != 0) { system("cls"); if(option == 1){ changeData(p); } else if(option == 2){ /*function here*/ } option = printMenu(); } }else{ cout << "File '" << fileName << "' did not open!" << endl; system("pause"); system("exit"); }//end if is_open // Memory Cleanup - p for (int i = 0; i < c; i++) { delete[] p[i]; } delete[] p; p = 0; //return 0 return 0; }
Comment