0

I am stuck with Caesar, validating the key. Before i use the atoi function, I want to check if argv consists of digits. I watched the linear search movie but is is to cryptic for me.

I have to itterate through the array en and check if every character is a digit or not. Unfortunately, I don't get the code right. Can you give me some advice?

#include <cs50.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
//variables
int i;

int main(int argc, string argv[])
{

    if (argc == 2)
    {
        printf("Success\n");

        for (i = 1; argv[i] != '\0'; i++)
            {
                printf("%s\n", argv[i]);
            }       
        // check te make sure that each argument is a digit
        if (isdigit(argv[i]) == 0)
            {
                printf("check\n");
            }
    }       
else
    {
        printf("./caesar key\n");
    }

return 1;
}
1

argv[] is a list of arguments introduced from the comand line. If you want to itterate through ever char in a particular argument you can do it by: argv[x][i] where x is the argument number and 'i' every character of that argument. For examble argv[1][0] would point to the first character of the second argument.

| improve this answer | |

You must log in to answer this question.

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