#include <cs50.h>
#include <stdio.h>
#include <string.h>
int main (int argc, string argv[])
{
string k= argv[1];
string p = argv[2];
if (argc==2)
{
p=GetString();
}
else
{
printf("There is an error in input");
return 1;
}
for (int a = 0, m = strlen(k); a<m; a++)
{
if ((k[a] > 'Z'&& k[a] < 'a' )|| (k[a]> 'z')|| (k[a]< 'A'))
{
printf("This is an invalid entry\n");
return 1;
}
}
int a = 0;
for (int i = 0, n = strlen(p); i<n; i++)
{
int m = strlen(k);
if((p[i] > 'Z'&& p[i] < 'a' )|| (p[i]> 'z')|| (p[i]< 'A'))
{
printf("%c",p[i]);
}
else
{
if (k[a] >=65 && k[a] <= 90)
{
(k[a] = k[a] - 65);
}
if (k[a] >=97 && k[a] <= 122)
{
(k[a] = k[a] - 97);
}
if((p[i] <= 'Z'&& p[i] >= 'A' ) && (p[i]+k[a] <= 'z'&& p[i]+k[a] >= 'a'))
{
(p[i] = p[i]+ k[a] -26);
printf("%c",p[i]);
}
else if((p[i]+k[a] <= 'Z'&& p[i]+k[a] >= 'A' )|| (p[i]+k[a] <= 'z'&& p[i]+k[a] >= 'a'))
{
(p[i] = p[i]+ k[a]);
printf("%c",p[i]);
}
else
{
(p[i]= p[i]+k[a]-26);
printf("%c",p[i]);
}
a++;
if (a>m)
{
(a= 0);
}
}
}
printf("\n");
return 0;
}
Please help, I have spent hours being stuck on this one last step for pset2.
Shown in the picture is part of my code for vigenere. What I am stuck on is that argv[2] cannot be successfully translated into the secret code I want because somehow not the whole "k" string (k string is my key string from argv[1]) is being read and executed. I've read my code over and over again but still can't find what is wrong.
Can someone please help me T_T
Thanks