Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9010809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:33:41+00:00 2026-06-16T02:33:41+00:00

Hi I took the following code from a program I’m writing to check a

  • 0

Hi I took the following code from a program I’m writing to check a user generated string against a dictionary as well as other validation.

My problem is that although my dictionary file is referenced correctly,the program gives the default “no dictionary found”.I can’t see clearly what I’m doing in error here,if anyone has any tips or pointers it would be appreciated,

Thanks.

        //variables for checkWordInFile

        #define gC_FOUND 99
        #define gC_NOT_FOUND -99





        //
        static bool certifyThat(bool condition, const char* error) {
            if(!condition) printf("%s", error);
            return !condition;
        }

        //method to validate a user generated password following password guidelines.
        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
            get_user_password:

            printf("\n\n\t\tEnter your password following password rules: ");
            scanf("%s", &password);


            iChar = countLetters(password,&iUpper,&iLower,&iSymbol,&iNumber,&iTotal);
            iUpper = countLetters(password,&iUpper,&iLower,&iSymbol,&iNumber,&iTotal);
            iLower =countLetters(password,&iUpper,&iLower,&iSymbol,&iNumber,&iTotal);
            iSymbol =countLetters(password,&iUpper,&iLower,&iSymbol,&iNumber,&iTotal);
            iNumber = countLetters(password,&iUpper,&iLower,&iSymbol,&iNumber,&iTotal);
            iTotal = countLetters(password,&iUpper,&iLower,&iSymbol,&iNumber,&iTotal);



            if(certifyThat(iUpper >= 2, "Not enough uppercase letters!!!\n")
             || certifyThat(iLower >= 2, "Not enough lowercase letters!!!\n")
             || certifyThat(iSymbol >= 1, "Not enough symbols!!!\n")
             || certifyThat(iNumber >= 2, "Not enough numbers!!!\n")
             || certifyThat(iTotal >= 9, "Not enough characters!!!\n")
             || certifyThat(iTotal <= 15, "Too many characters!!!\n"))

            goto get_user_password;

            iResult = checkWordInFile("dictionary.txt", password);

            if(certifyThat(iResult != gC_FOUND, "Password contains small common 3 letter word/s."))
            goto get_user_password;

            iResult = checkWordInFile("passHistory.txt",password);

            if(certifyThat(iResult != gC_FOUND, "Password contains previously used password."))
            goto get_user_password;


            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

        int checkWordInFile(char * fileName,char * theWord){

            FILE * fptr;
            char fileString[MAX + 1];
            int iFound = -99;
            //open the file
            fptr = fopen(fileName, "r");
            if (fptr == NULL)
            {
                printf("\nNo dictionary file\n");
                printf("\n\n\n");
                system("pause");
                return (0); // just exit the program
            }

            /* read the contents of the file */
            while( fgets(fileString, MAX, fptr) )
            {
                if( 0 == strcmp(theWord, fileString) )
                {
                    iFound = -99;
                }
            }

            fclose(fptr);

            return(0);



        }//end of checkwORDiNFile
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:33:43+00:00Added an answer on June 16, 2026 at 2:33 am

    The solution was to use strNcmp, this allows for the length of the word being searched for. Problem arises with the empty space in the buffer using strcmp,which is what called the default error message.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following line of code in my program which I took from
I took the following code from the examples page on Asio class tcp_connection :
Following code is to save image took from camera into photo album. if ([mediaType
While the following code is saving the image I took from my application into
I took the following code from http://blogs.msdn.com/b/jaredpar/archive/2008/05/16/switching-on-types.aspx static class TypeSwitch { public class CaseInfo
I have the following code for my fragment. I pretty much took this from
I'm using backbone.js, underscore.js and jQuery. I took the following sample code from http://jsfiddle.net/thomas/C9wew/6/
Running my script through Devel::NYTProf showed that the following portion of code took up
I took the example code from the Kendo UI demos at http://demos.kendoui.com/web/grid/remote-data.html , binding
I've took a simple piece of code from the NodeJS core (crypto) : ASSERT_IS_BUFFER(args[0]);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.