0
substitution.c:24:23: error: expected expression
    char* plaintext = get_string();
                      ^
/usr/include/cs50.h:109:53: note: expanded from macro 'get_string'
#define get_string(...) get_string(NULL, __VA_ARGS__)
                                                    ^
1 error generated.
<builtin>: recipe for target 'substitution' failed
make: *** [substitution] Error 1
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <cs50.h>

bool check(char *key);
int intkey(int a, char *key);

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        printf("Usage\n");
        return 1;
    }
    char *key = argv[1];

    if (!check(key))
    {
        return 1;
    }

    printf("plaintext: ");
    char* plaintext = get_string();
    printf("\nciphertext: ");

    for (int i = 0, len = strlen(plaintext); i < len; i++)
    {
        if (!isalpha(plaintext[i]))
        {
            printf("%c", plaintext[i]);
        }
        if (isupper(plaintext[i]))
        {
            int base = plaintext[i] - 'A';
            int change = (base + intkey(i, key)) % 26;
            int top = change +'A';
            printf("%c", top);
        }
        else
        {
            int base = plaintext[i] - 'a';
            int change = (base + intkey(i, key)) % 26;
            int top = change +'a';
            printf("%c", top);
        }
    }
    printf("\n");
    return 0;
}



int intkey(int a, char *key)
{
    char k = key[a % 26];
    if (isupper(k))
    {
        k = k - 'A';
    }
    else
    {
        k = k - 'a';
    }
    return k;
}


bool check(char *key)
{
    int length = strlen(key);
    if (length != 26)
    {
        printf("key length error\n");
        return 1;
    }
    char checkarray[length];
    for (int i = 0; i < length; i++)
    {
        checkarray[i] = 0;
    }
    for (int i = 0; i < length; i++)
    {
        if (!isalpha(key[i]))
        {
            printf("key contains characters other than alphabets\n");
            return 1;
        }
        if (isupper(key[i]))
        {
            checkarray[(int) key[i] - 'A'] += key[i];
            if (!isalpha(checkarray[(int) key[i] - 'A']))
            {
                printf("Same alphabet %c used multiple times.\n", key[i]);
                return 1;
            }
        }
        else
        {
            checkarray[(int) key[i] - 'a'] += key[i];
            if (!isalpha(checkarray[(int) key[i] - 'A']))
            {
                printf("Same alphabet %c used multiple times.\n", key[i]);
                return 1;
            }
        }
    }
    return true;
}
1

Your get_string() has no arguments, while in the lectures we've been taught to always insert a prompt (in the form of a string) in between the parentheses.

Try combining these two lines:

printf("plaintext: ");
char* plaintext = get_string();

into this one liner:

char* plaintext = get_string("plaintext: ");

You must log in to answer this question.

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