When I asked you in your other thread to post a self-contained example, I meant something like this.
Code:
//!!#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int shift(char c);
int main()
{
// Examples from https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher
char key[] = "LEMON";
char plaintext[] = "ATTACKATDAWN";
char result[] = "LXFOPVEFRNHR";
// Converts plain text to cipher text
for (int l = 0, o = strlen(plaintext); l < o; l++)
{
int m = (l % strlen(key));
if (islower(plaintext[l]))
{
char cipheredletter = (plaintext[l] + shift(key[m]) - 97) % 26 + 97;
printf("%c", cipheredletter);
}
else if (isupper(plaintext[l]))
{
char cipheredletter = (plaintext[l] + shift(key[m]) - 65) % 26 + 65;
printf("%c", cipheredletter);
}
else
{
char cipheredletter = plaintext[l];
printf("%c", cipheredletter);
}
}
printf("\n");
return 0;
}
int shift(char c)
// Converts alphabetical character to a numerical key
{
if (islower(c))
{
c = c - 97;
}
else
{
c = c - 65;
}
return c;
}
No guessing as to what to type in.
No need for mysterious header files like cs50.h
Now, starting from this, make an example which demonstrates the problem.
But I kinda know already, so
Code:
int m = (l % strlen(key));
if (islower(plaintext[l]))
{
char cipheredletter = (plaintext[l] + shift(key[m]) - 97) % 26 + 97;
printf("%c", cipheredletter);
}
to
Code:
if (islower(plaintext[l]))
{
char cipheredletter = (plaintext[l] + shift(key[m]) - 97) % 26 + 97;
printf("%c", cipheredletter);
m = (m+1) % strlen(key);
}