after rewriting my code again i faced some proplems, when i compile it with 'a' or other key it's not printing anything, and i'm checking if user not providing plaintext it should print messege but it won't, any pointers?
here's my code
#include stdio.h>
#include cs50.h>
#include string.h>
#include ctype.h>
int shift(char c);
int main (int argc, string argv[])
{
if (argc != 2 && !isalpha(argv[1]))
{
printf("Usage: ./vigenere keyword\n");
return 1;
}
string plaintext = get_string("plaintext: ");
if (plaintext == NULL)
{
printf("please provide an input to cipher\n");
return 1;
}
printf("ciphertext: ");
int n = strlen(argv[1]);
int key;
for (int i = 0; i < n; i++)
{
key = shift(argv[1][i]);
}
return key;
for (int i = 0, s = strlen(plaintext); i < s; i++)
{
if (isupper(plaintext[i]))
{
printf("%c", toupper(((plaintext[i] + key) - 65) % 26) + 65);
}
else if (islower(plaintext[i]))
{
printf("%c", tolower(((plaintext[i] + key) - 97) % 26) + 97);
}
else
{
printf("%c", plaintext[i]);
}
printf("\n");
}
}
int shift(char c)
{
if (isupper(c))
{
return c - 65;
}
return c - 97;
}