0

So actually I wrote the code for vigenere mostly from caesar and changing it a bit where needed. I am actually not sure if the way i tried to change the argument vector i took into a string and finding its length is correct or not. And can you please see what else is wrong?

#include<stdio.h>
#include<ctype.h>
#include<cs50.h>
#include<string.h>
int main(int argc,char* argv[1])
{
    char y;
    if(argc==2)
    {   string s=argv[1];
       int a=strlen(s);
       for(int c=0;c<a;c++)
       {
           if(isalpha(s[c])&&isupper(s[c])&&islower(s[c]))
           {
    printf("plaintext:");
    string st=get_string();
   int l=strlen(st);
      printf("ciphertext: ");
   for(int b=0;b<l;b++)
  {
if(isalpha(st[b]))
{
    if(isupper(st[b]))
    {
      for(int d=0;d<d%3;d++)
       {
            st[b]=((st[b]+(st[d]-65)))%26;
             y =st[b]+65;
           printf("%c",y);
      }
    }
   else
    {
      for(int d=0;d<d%3;d++)
       {
             st[b]=((st[b]+(st[d]-97)))%26;
             y=st[b]+97;
             printf("%c",y);
    }
}
}
 else
   {
      printf("%c",st[b]);
   }
 }

  printf("\n");
  return 0;
  }
 }
}
 else
 {
     printf("Enter the correct parameters\n");
     return(1);
 }
}

Thank you!! Hope the code is clear enough.

1

In general, I refuse to answer questions like "I do not know what's wrong with my code", it's a bad practice and, in my opinion; it goes against the honor code of the course. A good practice would be to ask specific questions about a portion of the code, what your doubts are, and show the errors you get. As for your code only a few notes:

int main(int argc,char* argv[1])

should be:

int main(int argc,char* argv[])

int argc,char* argv[] they are called formal parameters, and they allow to receive both arguments from the command line, however it is the first time that I see this and I do not know what effect it may have on the code.

The most serious error is the following:

if(isalpha(s[c])&&isupper(s[c])&&islower(s[c]))

tells us that the given character must be alphabetic (correct) and must be both uppercase and lowercase, that is, it is a condition that is never going to be fulfilled, so the following code is never going to be executed, it is simply it will run out of the for cycle, without any effect and we will exit the program when we enter. I hope this will start.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .