I've managed do everything in the caesar cipher problem, i.e. it does encrypt, checks for 2 cl arguments, except that I can't manage to check argv[1] for characters or digits. My code for this specific issue has changed so much that I'm not sure it makes sense anymore, if possible can someone explain how they'd do this in pseudocode and run me through the process so I can just completely rewrite this function. thank you in advance!


I think that you'll find everything you need here.

There are, for example, the isalpha and isdigit functions that could be interesting for you.

Hint : you can use them in a loop :)


ok so I have this

int is_digit(string b)
    for(int n = 0, l = strlen(argv[1]); n <= l - 1; n++)
            while (isdigit(argv[1][n]) == 0)
                printf("invalid input\n");
                return 1;
                printf("valid input\n");

it finally does actually check whether argv[1] contains digits and gives the correct response, however, now it doesn't execute all the code after this function, when I enter an invalid digit it says that it's incorrect and ends to program but when I enter a correct digit it just ends the program without executing the rest of the code. So my question now is how can I modify this loop to give a response that will continue the rest of the code. Also the else statement doesn't work at all so, again, I'm not sure how to continue (error: expected expression)

  • This doesn't compile. There are several reasons. First, please see, read and adopt what is written here. You should always have curly braces around code inside loops or conditions. Always. Here, for instance there is only printf("invalid input\n");, and not the two other lines that execute inside the while loop. Then remember, what's "inside" the else statement only executes if the previous if statement's condition was evaluated as false. Here, where is the if statement? Last thing, you don't use the b string. Why do you ask for it? – Aizen Aug 19 '16 at 11:18
  • Oh, and I forgot to tell, be sure to add the #include <ctype.h> line to your code. Otherwise, you won't be able to use the isdigit() function. – Aizen Aug 19 '16 at 11:29
  • Ahhhh I see, thank you very much! – Callum Gander Aug 23 '16 at 15:33

You must log in to answer this question.

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