0

when i check my program i get errors:

:) vigenere.c exists.
:( vigenere.c compiles.
    expected exit code 0, not 1
:| encrypts "a" as "a" using "a" as keyword
    can't check until a frown turns upside down
:| encrypts "barfoo" as "caqgon" using "baz" as keyword

Could you please tell me why it doesn`t work? Thanks.

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

int main(int argc, string argv[])
{
    if (argc !=2)
    {
        return 1;
    }

    string key = argv[1];
    int key_number = strlen(key);
    for (int m=o; m<key_number; m++)
    {
        if (isalpha(key[i]) == 0)
        {
            return 1;
        }
    }
    string line = "";
    printf("plaintext: %s", line);
    line = GetString();
    printf("ciphertext: ");
    for (int i=0, j=0, result=0, n=strlen(line); i<n; i++)
    {
        char letter = line[i];
        char key_new = key[(j) % key_number];

        if (isupper(key_new))
        {
            key_new -=65;
        }
        if (islower(key_new))
        {
            key_new -=97;
        } 
        if (isupper(letter))
        {
            result= (((letter + key_new -65) %26) +65);
            j++;
        }
        if (islower(letter))
        {
            result = (((letter+key_new -97) %26) +97);
            j++;
        }
        else  
        {
            result = letter;
        } 
        printf("%c", result);
    }
    printf("\n");
}
0

Your program doesn't compile. Did you try running it yourself before checking it with check50?

You've got this:

for (int m=o; m<key_number; m++)
    {
        if (isalpha(key[i]) == 0)
        {
            return 1;
        }
    }

but i has not been declared, so it's a compile error. Did you mean to use key[m]?

As a general guideline, it's better to compile and run your code to test it first, and use check50 as a final check.

edit to add


check50 will fail to compile because you are using GetString which was deprecated in the last year. I'm going to assume that you aren't using an current version of the CS50 IDE, as your code would also fail to compile there as well.

You need to replace GetString with get_string in order to use check50.

2
  • thanks for comment. Actually program works correctly, i run it and everything is fine. I made mentioned mistake when i was typing code here. So my question is the same: why there is a compile error? – Olenka Slyusar Nov 7 '17 at 19:35
  • @OlenkaSlyusar I edited my answer. – curiouskiwi Nov 7 '17 at 22:45

You must log in to answer this question.

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