0
int keyvalue = 0;

        int  n = strlen(argv[1]);
        char cipher;
        for (int i = 0; i < n; i++)
        {
            keyvalue++;    
        }
        for (int i = 0, s = strlen(plaintext); i < s; i++)
        {
            if (isupper(plaintext))
            {
                cipher = plaintext[i];
                printf("%c", shift((plaintext[i]) + keyvalue) % n);
            }
            else
            {
                printf("%c", (shift(plaintext[i]) + keyvalue) % n);
            }

        }


int shift(char c)

{

    int key = 0;
    if (islower(c))
    {
        key -= 'a';
    }
    else
    {
        key -= 'A';
    }
    return key;
}
0

Here's the problem:

if (isupper(plaintext))

isupper() takes a single char as input. This code is trying to shove an entire string down it's throat, so it chokes on it and throws an error.

You need to feed it one char at a time, using a for loop.

There may be other issues, but this is certainly throwing a seg fault.

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

3
  • well yeah it solved the seg fault proplem but you're right there's other issues but can you point me what's wrong i think it's the equation right? and how i can fix it? and Thank you for your help
    – ox0o
    Sep 7 '19 at 1:19
  • New problem gets a new question, with the most current version of the code. And please, include a more complete version of the code for testing. But please, for your own benefit, try to work out the issues first. If you can't, then include a full description of the problem, the symptoms, and some sample output. But I'll give you this: keyvalue is going to be set to the length of the key, which has nothing to do with the individual char values in the key. You need to rethink how to use the key. I recommend going back and watching the pset videos again.
    – Cliff B
    Sep 7 '19 at 1:36
  • okay i will and thanks for the hint
    – ox0o
    Sep 7 '19 at 1:47

You must log in to answer this question.

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