here's my code
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, string argv[])
{
// prints Usage : ./caesar key
if (argc == 1)
{
printf("Usage : ./caesar key\n");
}
// prints Usage : ./caesar key
else if (argc > 2)
{
printf("Usage : ./caesar key\n");
}
// following proceeds if argc = 2
else if (argc == 2)
{
for (int a = 0; a < strlen(argv[1]); a++)
{
char pt_1 = argv[1][a]; // checks each charecter of argv[1] is digit or not
// if argv[1] is a number then following happens
if (isdigit(pt_1))
{
// converts string argv[1] to an int;
int i = atoi(argv[1]);
// gets user input
string plaintext = get_string("plaintext:");
// basically writes ciphertext & performs the rest of the stuff afterwards
printf("ciphertext: ");
for (int b = 0; b < strlen(plaintext); b++)
{
// following proceeds if each charecter of plaintext is an alphabet
if (isalpha(plaintext[b]))
{
// following proceeds if the alphabet is Uppercase
if (isupper(plaintext[b]))
{
int p = plaintext[b] % 65;
int c = (p + i) % 26;
int z = c + 65;
printf("%c", z);
}
// following proceeds if the alphabet is Lowercase
else if (islower(plaintext[b]))
{
int p = plaintext[b] % 97;
int c = (p + i) % 26;
int z = c + 97;
printf("%c", z);
}
}
// prints anyother charecter which is not an alphabet as it is
else
{
printf("%c", plaintext[b]);
}
}
}
// prints Usage : ./caesar key even though argc = 2 but argv[1] is not a number
else if (isalpha(pt_1))
{
printf("Usage : ./caesar key\n");
return 1;
}
}
printf("\n");
}
}
error 0- So after giving commant line argument "./caesar 65" I get a prompt saying "plaintext:" after typing input as "burfoo" i get "cyphertext: onesubbplaintext:". It is clearly printing "plaintext:" again. why is this happening? Also when I type "burfoo" again I get the output as cyphertext: onesubb.
error 1- what is "handles lack of key"? then it says "expected exit code 1, not 0". what doe this mean? error 2- what is "handles non-numeric key"? then it says "timed out while waiting for program to exit". what is this?
error 3- what is "handles too many arguments"? Again it says "expected exit code 1, not 0". what doe this mean?