我有以下方法來生成一個字符串必須滿足要求,但如果驗證要求不符合,我需要某種子句來回送到用戶輸入。我知道在Java中有一個後續的閱讀,但我不知道在C是需要的代碼是什麼,也不認爲我的其他人,如果統計是正確的語法,如果任何人都可以發現錯誤。一些提示或建議將是有益的, 謝謝。回到用戶輸入驗證C
void validatePass()
{
FILE *fptr;
char password[MAX+1];
int iChar,iUpper,iLower,iSymbol,iNumber,iTotal,iResult,iCount;
//shows user password guidelines
printf("\n\n\t\tPassword rules: ");
printf("\n\n\t\t 1. Passwords must be at least 9 characters long and less than 15 characters. ");
printf("\n\n\t\t 2. Passwords must have at least 2 numbers in them.");
printf("\n\n\t\t 3. Passwords must have at least 2 uppercase letters and 2 lowercase letters in them.");
printf("\n\n\t\t 4. Passwords must have at least 1 symbol in them (eg ?, $, £, %).");
printf("\n\n\t\t 5. Passwords may not have small, common words in them eg hat, pow or ate.");
//gets user password input
printf("\n\n\t\tEnter your password following password rules: ");
scanf("%s", &password);
iChar = countLetters(password,&iUpper,&iLower,&iSymbol,&iNumber,&iTotal);
if(iUpper < 2)
{
printf("Not enough uppercase letters!!!\n");
}
else if(iLower < 2)
{
printf("Not enough lowercase letters!!!\n");
}
else if(iSymbol < 1)
{
printf("Not enough symbols!!!\n");
}
else if(iNumber < 2)
{
printf("Not enough numbers!!!\n");
}
else if(iTotal < 9 && iTotal > 15)
{
printf("Not enough characters!!!\n");
}
iResult = checkWordInFile("dictionary.txt",password);
if(iResult == gC_FOUND)
{
printf("\nFound your word in the dictionary");
}
else if
{
printf("\nCould not find your word in the dictionary");
}
iResult = checkWordInFile("passHistory.txt",password);
else if(iResult == gC_FOUND)
{
printf("\nPassword used");
}
else if
{
printf("\nOk to use!");
}
else
{
printf("\n\n\n Your new password is verified ");
printf(password);
}
//writing password to passHistroy file.
fptr = fopen("passHistory.txt", "w"); // create or open the file
for(iCount = 0; iCount < 8; iCount++)
{
fprintf(fptr, "%s\n", password[iCount]);
}
fclose(fptr);
printf("\n\n\n");
system("pause");
}//end validatePass method
如何實現這個do..while循環在我的代碼,我不知道在這種情況下,由於 –