Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use a goto. It's one of the few cases where it's warranted.</p> <p>Here's an example. As you can see, it's a lot cleaner than a <code>while(0)</code>, and will make the compiler complain less with <code>-Wall</code>, too!</p> <pre><code>// Returns whether or not the condition failed, printing the // given error if it did. static bool verifyThat(bool condition, const char* error) { if(!condition) printf("%s", error); return !condition; } 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."); get_user_password: printf("\n\n\t\tEnter your password following password rules: "); scanf("%s", &amp;password); iChar = countLetters(password,&amp;iUpper,&amp;iLower,&amp;iSymbol,&amp;iNumber,&amp;iTotal); iUpper = ... iLower = ... iSymbol = ... iNumber = ... iTotal = ... if(verifyThat(iUpper &gt;= 2, "Not enough uppercase letters!!!\n") || verifyThat(iLower &gt;= 2, "Not enough lowercase letters!!!\n") || verifyThat(iSymbol &gt;= 1, "Not enough symbols!!!\n") || verifyThat(iNumber &gt;= 2, "Not enough numbers!!!\n") || verifyThat(iTotal &gt;= 9, "Not enough characters!!!\n") || verifyThat(iTotal &lt;= 15, "Too many characters!!!\n")) goto get_user_password; iResult = checkWordInFile("dictionary.txt", password); if(verifyThat(iResult != gC_FOUND, "Password used.")) goto get_user_password; printf("Your new password is verified."); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload