I'm having a problem with argv[]: the code doesn't seem to 'see' it!! With a key that's either too long or too short, the program behaves as expected (prints out error message, exits).

But if I input a key that's one string long, nothing happens. I exit the program, and that's all.

To see what's wrong I'm trying to have the program print the key: nothing happens.

I have no idea why, at this point.

Help would be much appreciated!

(I'm just copying and pasting the first part of the code)

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

int main(int argc, string argv[])

//first I check whether the user has inputed a key made of more than one element

    if (argc != 2)
        printf("Usage: ./caesar key, key should be a positive integer");

    return 1;


//Now I'm excluding non-numeric keys. I check every char of argv [1] with isdigit. I do it by implementing a loop:

    for (int i = 0; i < strlen(argv[1]); i++)
        if (isdigit(argv[1][i]) == 0)
            return 1;

1 Answer 1


It's because you have return 1; after your if statement, that will just exit the program in that line and will not proceed to the next lines. That return should be inside your if statement therefore it will only be executed if the if statement is true.

You must log in to answer this question.

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