I'm trying to assign new User Input values into a struct in DevC++. But whenever it gets to the point when the user values are being assigned to the struct, the program crashes and Windows will say it stopped working.
Here's the struct:
struct users{ string uCode; string lName; string fName; string mInit; char type; char gender; } users_t[10]; And here's the function that performs the assignment:
void createAccount(){ string newUCode; string newLName; string newFName; string newMInit; char newGender; char newType; system("CLS"); showBordersMain(); gotoxy(30, 6); cout << "<!-- ACCOUNT CREATION -->"; gotoxy(20, 10); cout << "USER CODE : "; cin >> newUCode; if (newUCode.length() > 5){ gotoxy(20, 17); cout << "USER CODE MUST BE 5 CHARACTERS IN LENGTH.\n"; system("PAUSE"); createAccount(); } for (int i = 0; i < uCount - 1; i++){ if (newUCode == users_t[i].uCode){ gotoxy(20, 17); cout << "USER CODE ALREADY EXISTS!\n"; system("PAUSE"); createAccount(); } } gotoxy(20, 11); cout << "LAST NAME : "; gotoxy(20, 12); cout << "FIRST NAME : "; gotoxy(20, 13); cout << "MIDDLE INITIAL : "; gotoxy(20, 14); cout << "GENDER [M/F] : "; gotoxy(20, 15); cout << "ACCOUNT TYPE [A/C]: "; gotoxy(40, 11); cin >> newLName; gotoxy(40, 12); cin >> newFName; gotoxy(40, 13); cin >> newMInit; gotoxy(40, 14); cin >> newGender; gotoxy(40, 15); cin >> newType; //Problem starts here users_t[uCount].uCode = newUCode; //Program crashes before it reaches this point users_t[uCount].lName = newLName; users_t[uCount].fName = newFName; users_t[uCount].mInit = newMInit; users_t[uCount].gender = newGender; users_t[uCount].type = newType; gotoxy(20, 17); cout << "NEW USER ADDED!\n"; system("PAUSE"); } Another thing, I had gotoxy() defined, in case you're wondering, and I'm using Orwell's DevC++ 5.10.
uCountdefined?0touCount-1, I can only assume thatuCountis10, makingusers_t[uCount]an out of bounds access. Lots of guessing here, since the relevant portions of code are not included.