The for loop is not running and I cant figure out why. Everything looks good to me. I need some fresh eyes. Thanks guys!
#define _XOPEN_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <cs50.h>
#include <crypt.h>
#include <stdlib.h>
int main(int argc, string argv[])
{
if (argc == 2)
{
string key = (argv[1]);
int letter;
char range[60] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
string plainText = get_string("plaintext: ");
int keylength = strlen(argv[1]);
printf("ciphertext: ");
int j = 0;
printf("%lu", strlen(plainText));
for (int i = 0; i < strlen(plainText - 1); i++)
{
printf("IM HEEERRREEEEE");
if(j == keylength - 1)
{
j = 0;
}
letter = plainText[i];
printf("char %d - index %d",letter,i);
if (letter > 96 && letter < 123)//if lowercase
{
if ((letter + key[j]) > 121)
{
printf("%c", range[(((letter - 'a') + (key[j] - 'a')) % 26)]);
printf("%d, %d", letter, key[j]);
j++;
}
else
{
printf("%c", range[((letter - 'a') + (key[j] - 'a'))]);
j++;
}
}
else if (letter > 64 && letter < 91)//if uppercase
{
if ((letter + key[j]) > 89)
{
printf("%c", range[((((letter - 'A') + (key[j] - 'A')) % 26) + 26)]);
j++;
}
else
{
printf("%c", range[(((letter - 'A')+ (key[j] - 'A') - 'A') + 26)]);
j++;
}
}
else // if special character
{
printf("%c", letter);
j++;
}
}
printf("\n");
}
else
{
printf("Please input the key\n");
return 1;
}
return 0;
}