1

After spending pretty much a whole day on this, I have gotten it to work fine, it does all that was demanded but when submitted, I am still getting 1/5 on correctness. :( someone tell me if I left something out

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

int main(int argc, string argv[])
{ 
    //check if user added a key
    if (argc != 2)
    {
        printf("Usage: ./caesar key\n");
        return 1;
    }
    for (int i = 0, q = strlen(argv[1]); i < q; i++ )
    {
        if(isalpha(argv[1][i])){
            printf("Usage: ./caesar key\n");
            return 1;
        }
    }

    //use atoi to convert user key to int
   int k = atoi(argv[1]) % 26;
    if (k < 0)
    {
        printf("Usage: ./caesar key\n");
        return 1;
    }
    else
    {
        string name = get_string("plaintext :  ");
        printf("ciphertext : ");
        //iterate over every character in the message
        for (int i = 0, n = strlen(name); i<n; i++ )
        {
           //check if character is small
          if islower(name[i])
            printf("%c", (((name[i] + k) - 97) % 26) + 97);
            //check if character is upper case
          else if isupper(name[i])
            printf("%c", (((name[i] + k) - 65) % 26) + 65);
            //else print the character as it is
          else
            printf("%c", name[i]);
        }
        printf("\n");
        return 0;
    }
}

1 Answer 1

4

The output does not match the spec. This plaintext : should be this plaintext:. The same with ciphertext:. There is no space between the word and the :. While this may seem "overly strict", it is good practice for when you write code for a boss or a customer and there is real money on the line.

You must log in to answer this question.

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