0

Been struggling with this all morning and grateful for any help please!

I'm aware that it's not the most elegant code but below weems to work OK with most invalid input that I've thrown at it so far, except for parentheses (see screengrab of terminal immediately below).

Thanks!

SiƓn

enter image description here

//Include libraries
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <math.h>
#include <string.h>

//Declare functions

//Main programme
int main(int argc, string argv[])
{

//Validate CLA input for use as key
    if (argc == 2)
    {
        int x;
        for (x = 0; argv[1][x] != '\0'; ++x)
        {
            if (!isdigit(argv[1][x]))
            {
                printf("Usage: ./caesar key");
                return 1;
            }
            else if (x == strlen(argv[1]-1))
            {
                printf("Success");
                return 0;
            }
        }
    }
    else
    {
        printf("Usage: ./caesar key");
        return 1;
    }
}
0

This has nothing to do with your code, actually. "bash" is the command line language, and it also wants your parenthesis to be balanced. It's not parsing ) as a string, it's parsing it as an end parenthesis that needs a start one to balance it. You don't have to worry about this in your program, because it's never actually touching your program. If you want to input the string ) to test your program, you can do ./caesar ')', and bash will strip the single quotes and input the string ) to your program.

| improve this answer | |
  • Thanks @Llenk - really appreciate quick reassurance on this. Have now completed and submitted by code and had it approved so confirming for others that your answer is ace! – Sion Williams Jun 17 at 12:16

You must log in to answer this question.

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