0
        string keyword = argv[1];

for(int i = 0; i<= strlen(keyword); i++)
{
         if(!isalpha(keyword[i]))
        {
         printf("error\n");
         return 1;   
        }

        else
        {
        break;
        }  
}

when there is a non-alphabetical character, after an alphabetical character in argv[1], for example, ./vigenere word1 it doesn't print the error or return 1 but, if the non-alphabetical character is before the alphabetical character in argv[1], for example ./vigenere 1word it prints the error and returns 1.

I'm not sure how to fix this problem.

1 Answer 1

1
i<= strlen(keyword)

keep in mind that keyword begins with the zero subscript so that if its length is given by strlen the one index is strlen(keyword) - 1, the correct statement would be:

i < strlen(keyword)

The problem is given by the statement

else
        {
        break;
        } 

It seems that if the first character is non-alphabetic the program behaves as expected, but if there is an alphabetic character is executed the sentence else, that leaves the loop and no more checking is done, the solution is to delete the sentence else

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .