My code for CS50 pset2 Vigenere cypher is as follows. Please help me find the bug. This code basically does nothing when the key includes the letter 'a'. It says "Floating Point Exception". I don't know what that means. Please go through the code and tell me what the bug is.
#include<stdio.h>
#include<cs50.h>
#include<ctype.h>
#include<string.h>
int main(int argc, string argv[])
{
//check if there are only two command line arguments//
if (argc!=2)
{
printf("Please enter a valid input!\n");
return 1;
};
string key = argv[1];
for(int i=0, n=strlen(key); i < n; i++)
{
//check if there is any number in the key//
if(!isalpha(key[i]))
{
printf("Invalid Key!\n");
return 1;
};
//converting the key into ints.//
if(islower(key[i]))
{
key[i] = key[i] - 'a';
}
else if(isupper(key[i]))
{
key[i] = key[i] - 'A';
};
};
//prompt user for the string//
string s = GetString();
int c;
int k;
int stln = strlen(s);
int kyln = strlen(key);
for(int j = 0, m = strlen(s); j < m; j++)
{
if(islower(s[j]))
{
s[j] = s[j] - 'a';
//for wrapping around the key//
if(stln > kyln)
{
k = j % strlen(key);
c = (s[j] + key[k]) % 26;
s[j] = 'a' + c;
}
else
{
c = (s[j] + key[j]) % 26;
s[j] = 'a' + c;
};
}
else if (isupper(s[j]))
{
s[j] = s[j] - 'A';
//for wrapping around the key//
k = j % strlen(key);
if(stln > kyln)
{
c = (s[j] + key[k]) % 26;
s[j] = 'A' + c;
}
else
{
c = (s[j] + key[j]) % 26;
s[j] = 'A' + c;
};
};
};
printf("%s\n", s);
};