mardi 25 août 2020

My code will print error message twice and still run

I am having an issue where my code should look for a duplicate value and throw an error if true otherwise set a bool value to "true". But for some reason it is printing the error message twice and still executing the rest of the code. I even tried another option but both gave the same result (the commented out if statement)Please help me out here:

''''''''

bool key_check(string argv[])
{

int string_c = strlen(argv[1]);
bool key_c;
int dup[string_c];

if (string_c == 26)
{

    for (int i = 0; i < string_c; i++)
    {
        if(isalpha(argv[1][i]))
        {
                if(strcmp(argv[1], argv[1]) != 0)
                {
                    key_c= true;
                }
                else
                {   //this line is being printed twice and instead of terminating code it allows it to run
                    printf("Key must not contain duplicates.\n");
                    return 1;
                  
                }

                /*if(dup[argv[1][i] - 65] == false && dup[argv[1][i] - 97] == false )
                {
                    key_c= true;
                }
                else
                {
                  printf("Key must not contain duplicates. %c \n", argv[1][i]);
                  key_c = false;
                  return 1;
                }*/
            //}
        }
        else
        {
            printf("Key must only contain characters. \n");
            key_c= false;
            return 1;

        }
    }
}
else
{
   printf("Key must contain 26 characters. \n");
    key_c= false;
}

return key_c;

}

''''''''

Aucun commentaire:

Enregistrer un commentaire