In command line argument,it should not accept argv[1] as a numeric or any other.It should accept only alphabetic and that argv[1] is treated as key which is to be added with plaintext.so,for that i have written a condition if(!alpha()).But still it is accepting argv[1] as nummeric.Please help me out with this.
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argc,string argv[])
{
if(argc==2)
{ //to get input from user
printf("plaintext: ");
string s=get_string();
//to print output
printf("ciphertext: ");
//to read plaintext till end
for(int i=0,l=strlen(s);i<l;i++)
{ //to assign argv[1] to key
string key=argv[1];
if(!isalpha(key[i]))
{
printf("Usage: ./vigenere k\n");
return 1;
}
//to check if it is alphabetical
else if(isalpha(s[i])&&isalpha(key[i]))
{
for(int j=0,n=strlen(key);j<n;j++)
{
if(islower(s[i])&&islower(key[j]))
{
s[i]=(((s[i]-97)+((tolower(key[j])-97)%26))%26)+97;
}
else if(isupper(s[i])&&isupper(key[j]))
{
s[i]=(((s[i]-65)+((toupper(key[j])-65)%26))%26)+65;
}
}//for closed
printf("%c",s[i]);
}//else if closed
}//for closed
printf("\n");
return 0;
}//if closed
else if(argc!=2)
{
printf("Usage: ./vigenere k\n");
return 1;
}
}//main closed