My Vigenere code is printing incorrectly. I can't pinpoint the source of it, but here's my code.
int main(int argc, char *argv[])
{
if(argc < 2)
{
printf("waoh mahn!\n");
return(1);
}
else if(argc > 2)
{
printf("waoh mahn!\n");
return(1);
}
string key = argv[1];
int c = 0;
int keylength = 0;
string input = GetString();
for(int i = 0; i < strlen(input); i++)
{
if(isalpha(input[i]))
{
for(c = 0; c < key[i]; c++)
{
if(input[i] == 'z')
input[i] = 'a';
else if(input[i] == 'Z')
input[i] = 'A';
else input[i]++;
keylength++;
}
}
}
printf("%s\n", input);
}
Here's the check50
:) vigenere.c exists
:) vigenere.c compiles
:( encrypts "a" as "a" using "a" as keyword
\ expected output, but not "t\n"
:( encrypts "world, say hello!" as "xoqmd, rby gflkp!" using "baz" as keyword
\ expected output, but not "qhjli, qyh bfrgi!\n"
:( encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword
\ expected output, but not "PtDFti\n"
:( encrypts "BARFOO" as "CAQGON" using "BAZ" as keyword
\ expected output, but not "PNDFTI\n"
:) handles lack of argv[1]
:) handles argc > 2
:( rejects "Hax0r2" as keyword
\ expected output, not a prompt for input
Any idea how I might go about having it print correctly?