Hello all, I am getting a segmentation fault when trying to access an array... I know this is silly, am I overlooking something? What the hell? The problem seems to occur when accessing an array from the bigFish function. Please teach me..
Code:#include #include #include #include using namespace std; struct fish{ int contestant[99999]; int fishNumber[99999]; float fishWeight[99999];}; void readFiles(int contest[20], string name[20], int fishNum[5], string fishType[5], fish fishStruct); void bigFish(int contest[20], string name[20], int fishNum[5], string fishType[5], fish fishStruct); int main() { fish fishStruct; int choice = 0; //choice in menu cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); cout.precision(2); int contest[20]; string name[20]; int fishNum[5]; string fishType[5]; readFiles(contest, name, fishNum, fishType, fishStruct); cout<<"MENU: PLEASE MAKE A SELECTION"<<endl<<endl; cout<<"1. Display all data for a contestant"<<endl; cout<<"2. Display total catch weight for fish type"<<endl; cout<<"3. Display largest fish caught"<<endl<<endl; cout<<"Choose and option between 1-3"<<endl; cin>>choice; if (choice == 3) bigFish(contest, name, fishNum, fishType, fishStruct); return 0; } void readFiles(int contest[20], string name[20], int fishNum[5], string fishType[5], fish fishStruct) { ifstream inFile; inFile.open("contestantname.data"); if (!inFile) { cout<<"contestantname.data not found"<<endl; } //clearing out the array for(int i = 0; i < 20; i++) { contest[i]=0; name[i] = " "; } int count1 = 0; while(inFile) { inFile>>contest[count1]; inFile>>name[count1]; cout<<name[count1]<<endl; count1++; } inFile.close(); inFile.open("fishtype.data"); if (!inFile) { cout<<"fishtype.data not found"<<endl; } //clearing out the array for(int i = 0; i < 20; i++) { fishNum[i]=0; } int count2 = 0; while(inFile) { inFile>>fishNum[count2]; inFile>>fishType[count2]; count2++; } inFile.close(); inFile.open("catch.data"); if (!inFile) { cout<<"catch.data not found"<<endl; } //clearing out the array for(int i = 0; i < 20; i++) { fishStruct.contestant[i]=0; fishStruct.fishNumber[i]=0; fishStruct.fishWeight[i]=0; } int count3 = 0; while(inFile) { inFile>>fishStruct.contestant[count3]; inFile>>fishStruct.fishNumber[count3]; inFile>>fishStruct.fishWeight[count3]; count3++; } inFile.close(); } void bigFish(int contest[20], string name[20], int fishNum[5], string fishType[5], fish fishStruct) { int num = 0; //temp contestant number int totalWeight = 0; //weight for each contestant string tempName; //temp contestant name cout<<"Please enter contestant number"<<endl; cin>>num; for(int i = 0; i < 20; i++) { cout<<name[i]; //THIS IS WHERE //I AM TROUBLED } }



LinkBack URL
About LinkBacks



