tags:

views:

72

answers:

2
bool print_date(Date *d, char **argv) {

        if (isdigit(*argv+1)) {
                return printf("is d");
        } else {
                return printf("is not d");
        }

}

The above function don't work. *argv+1 is the user input, is it a string or what types when passing in? anyone can help?

 int main(int argc, char *argv[])
 {

  Date d;

  get_date(&d, argv);


 }
+3  A: 

*argv+1 computes the address to the first character of the 0-th argument (that is the executable name) and adds 1 to shift to second char of it.. I don't think this is what you want to do.

You could try by using argv[1], this will mean the first argument after the executable name, as a char *.

Jack
thanks your comment , but isdigit still not working
friends
of course it is not working, `isdigit` assumes a single char while using `argv[1]` will give you the whole string, not just a char. You should dereference it again to obtain the actual `char` type.
Jack
how to dereference it? i'm a beignning of C
friends
@friends, try `argv[1][0]` -- this will be the first character of the first argument (and also consider checking argc to be sure that at least one argument was passed).
to dereference you use the `*` operator. Or you can go with user470379 solution that is quite straightforward..
Jack
@user470379 thaks, i've checked argv[1] is exactly what i want
friends
if (isdigit(*argv[1])) { return printf("is d"); } else { return printf("is not d"); }
friends
finished! thanks
friends
you are welcome :)
Jack
A: 

I am guessing that what you really want is *(argv + 1). The way you have it written is that it will dereference the first character of the program, add one and then test if it is a digit.

doron