My logic seems to be working good. But the problem comes near the symbols and spaces. Can you help me why?
#include<stdio.h>
#include<ctype.h>
#include<cs50.h>
#include<string.h>
int main(int argc,char* argv[1])
{
char y;
if(argc==2)
{
int k = atoi(argv[1]);
printf("plaintext:");
string s=get_string();
int l=strlen(s);
printf("ciphertext: ");
for(int b=0;b<l;b++)
{
if(isalpha(s[b]))
{
if(isupper(s[b]))
{
for(int a=0;a<l;a++)
{
s[a]=s[a]-65;
s[a]=(s[a]+k)%26;
y =s[a]+65;
printf("%c",y);
}
}
else
{
for(int a=0;a<l;a++)
{
s[a]=s[a]-97;
s[a]=(s[a]+k)%26;
y=s[a]+97;
printf("%c",y);
}
}
}
else
{
printf("%c",s[b]);
}
}
printf("\n");
return 0;
}
else
{
printf("Enter the correct parameters\n");
return(1);
}
}
Hope you can help!!