0

I'm stuck on the vigenere assignment. I think I have some parentheses in the wrong place but it might be something else aswell. Can someone give me a hint? Thanks a lot! https://pastebin.com/yMbCysNA

#import <stdio.h>
#import <cs50.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main (int argc, string argv[])

int i;

{ 

    //checking if te input has 2 arguments
    if (argc != 2 ) { printf("try to use 2 arguments\n"); return 1;
    }
    //convert argv to string "key"
    string key = argv[1];

    if (argc == 2) 
    {
        //plaintext input
    string text = get_string("Enter plaintext: ");
        printf("ciphertext: ");

        // print out the plaintext letter by letter     
        for (int i =0, n = strlen(text); i < n ; i++)

         // here is where I struggle, the sub script to wraparound the key only if its an alphabetic character.   
        if isalpha(text[i])  {
          for (int keyindex = 0, nk = strlen(key); keyindex < nk; keyindex++)
            keyindex % nk;
             }

             // convert the plaintext to ciphertext 

                if islower(text[i]) 
                    printf("%c", (((text[i] + key[keyindex]) - 97) % 26) + 97); 
                else if isupper(text[i])
                    printf("%c", (((text[i] + key[keyindex]) - 65) % 26) + 65);

                else printf("%c",text[i]);

        printf("\n");
    }

}

1 Answer 1

2

Simple enough. Look at the first few lines:

int main (int argc, string argv[])

int i;

{

The first thing that must follow the int main line is an opening curly brace. The code above has a declaration before the curly brace.

The main function must be structured like this:

int main (int argc, string argv[])
{ 
   //  ALL of the code for main must be placed between these curly braces.
    ....
}

There are more issues to follow, but you need a chance to work on them and develop your debugging skills. Don't feel frustrated that you're making mistakes now. It's actually a good thing. You'll learn what the errors are and how to fix them, and will make them far less often over time. You'll also learn to recognize similar errors and should better know how to handle them. One of the most important skills a programmer needs is how to debug. This will be good practice. ;-)

If you have other problems with this that you just can't solve, please post as a new question.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

0

You must log in to answer this question.

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