as the title says, I have most of the characters correct in the output compared to what it says in the instructions for pset2 Vigenere but a few of them are off, any help would be appreciated!
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, string argv[])
{
if(argc != 2)
{
printf("IDIOT!\n");
return 1;
}
string key = argv[1];
for (int n = 0, keylength = strlen(key); n < keylength; n++)
{
if(!isalpha(key[n]))
{
printf("You must enter a keyword with only letters, no numbers.\n");
return 1;
}
}
string p = GetString();
int l = strlen(key);
for(int i = 0, j = 0, n = strlen(p); i < n; i++)
{
if(isupper(p[i]))
{
char upper = (p[i] - 65) + (key[j%l] - 97) %26 + 65;
printf("%c", upper);
j++;
}
else if(islower(p[i]))
{
char lower = (p[i] - 97) + (key[j%l] - 97) %26 + 97;
printf("%c", lower);
j++;
}
else if(isspace(p[i]))
{
printf(" ");
}
}
printf("\n");
return 0;
}
when I input this with the keyword "bacon"
Meet me at the park at eleven am
I get this:
Neg� zf av �uf pc�x bt gzrwep oz
Which is close except for the unknown unicode characters
(Note: edited for clarity of the problem) Suggestions?