I have been reading a previous question, to try to figure out a problem. The problem regards leaving \n in the input buffer, thus i am having to press enter twice. One member replied stating using cin.ignore should sort this. I have tried in vain but it just doesnt want to play. I have tried cin.ignore (254,'\n''); etc etc (and a load of other things too.) If you could just scan my code and see why I need to press enter twice on each input I would be most grateful...When using cin.ignore(etc) I actually had to press enter THREE times to continue. Thanx.
const int PASSQUANT=10;
const int MAX_CHARS=7;
const int ATTEMPTS=3;
void main()
{
char Password [PASSQUANT][MAX_CHARS];
char User_Password[MAX_CHARS], Buffer[255];////255 max keyboard buffer
int Trys=0;
int ReturnVal;
for (int i=0;i<PASSQUANT;i++)
{
cout << "Please enter supervisor password for level "<<i+1<< "access ";
cin.getline(Buffer,255);///use the temp buffer to validate length
while (strlen(Buffer) !=(MAX_CHARS-1))//now checking password length
{
cout << "INCORRECT PASSWORD LENGTH ! ";
cout << "\nPlease enter supervisor password for level "<<i+1<< "access ";
cin.getline(Buffer,255); //obtain password again
}
strcpy (Password[i],Buffer); //put the validated password into real variable
} //end first for loop
clrscr();
etc etc
Program goes on etc, on debugger, all 10 passwords are shown niceley in the array with end of markers etc....just have to press enter twice!!
![]()
borland 5 proff



LinkBack URL
About LinkBacks




