currently i am solving pset2 vigenere cipher problem.bellow is my code.problem is that when i execute this code(this code is only for uppercase of key and plain text)the output is fine.but when i want to check that key was also in uppercase it will give output only the length of key using in argv[1].(when i replace this line"if (isupper(text[a]))" with this one "if ((isupper(text[a])) && (isupper(argv[1][b])) please help me.
#include<cs50.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
int main(int argc,string argv[])
{
if (argc !=2)
{
printf("command line argument error\n");
return 1;
}
for ( int i = 0; i < strlen(argv[1]); i++)
{
if (!isalpha(argv[1][i]))
{
printf("command line argument error\n");
return 1;
}
}
printf("plaintext:");
string text = get_string();
printf("ciphertext:");
for (int a = 0, b = 0,n = strlen(text); a < n; a++)
{
char key = argv[1][(b) % strlen(argv[1])];
if (isalpha(text[a]))
{
if (isupper(text[a]))
{
char letter = text[a] - 65;
char cipher = (letter + (key-65)%26)+65;
b++;
printf("%c", cipher);
}
}
}
}
{}
button or pressCtrl
+K
to indent that code by four spaces. A block of lines all starting with at least four spaces is considered code (those four spaces are removed on rendering). Outside code blocks, the#
is considered markdown for a caption, that's why your#include
statements all look weird.*
).