0

enter image description here

#include <stdio.h>
#include <cs50.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>  //atoi ?

bool is_valid_key( string s);
// Validate the key as a string
// make sure each character is a digit
void encrypt(string plaintext, string chiphertext, int k);

int main (int argc, string argv[])
// Validate command line arguments
{
  if (argc != 2 || !is_valid_key(argv[1]))   // Valid key
  {
      printf("Usage: ./caesar key");
      return 1;
  }
  int k = atoi(argv[1]);   // #include <stdlib.h>....atoi
  string s =  get_string("plaintext: ");
  int n = strlen(s);
  char ciphertext[n + 1];
  encrypt(s, ciphertext, k );

  printf("ciphertext: %s/m", ciphertext);
    return 0;
    }

      void encrypt(string plaintext, string ciphertext, int k)

    {

      int i = 0;


      for (i = 0; i < strlen(plaintext);  i++ )
    {

       char ch = plaintext[i];


       if(isalpha(ch))
       {
       //Encrypt
       // ci = (pi + k) % 26
       //pi = current character
         char temp = tolower(ch);
         int pi = temp  - 'a';
         char ci = ((pi + k) % 26) + 'a';
         ciphertext[i] = islower(ch ? ci : toupper(ci));
       }
       else
       {
           ciphertext[i] = ch;
       }

       }
        ciphertext[i] = '\0';
       }

         bool is_valid_key( string s)

        //write a for loop function to validate string
       {
        for (int i = 0;  i < strlen(s); i++)
       {
            char ch = s[i];
            if (!isdigit(ch))
            {
                return false;
            }
        }
        return true;
    }
0

Simple.

"Caesar" is not the same as "caesar".

The filename must match, including capitalization.

Next, if you haven't compiled AND TESTED your program, and made sure it works correctly, it's way too soon to be submitting the code for grading. And after testing it, it's clear that this program is not ready to be submitted.

4
  • Thanks I clearly miss the Ceaser "rookie error" but I'm still not compiling Oct 21 '20 at 23:50
  • ~/pset2/ceaser/ $ ./ceaser 1 plaintext: a ciphertext: /m~/pset2/ceaser/ $ Oct 21 '20 at 23:50
  • Based on your second comment, you've both compiled and executed the program. Not saying that it executes correctly. That's an entirely different matter. BTW, if you want to have the code print a line feed, the code that should be in the printf statement is \n, not /m That's also part of your problem.
    – Cliff B
    Oct 22 '20 at 0:18
  • I actually went and copied someone else code to see if would compile but it still the same thing it won't execute "/m~pset2/ceaser/$" so I went back to my code Oct 22 '20 at 0:28

You must log in to answer this question.

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