Question: So I have an assignment to figure out whether a number on the command line is either an integer or a double.

I have it mostly figured it out by doing:

```
sscanf(argv[x], "%lf", &d)

```

Where "d" is a double. I then cast it to an int and then subtract "d" with itself to check to see if it is 0.0 as such.

```
d - (int)d == 0.0

```

My problem is if the command line arguments contains doubles that can be technically classified as ints.

I need to classify 3.0 as a double whereas my solution considers it an int. 
For example initializing the program.

```
a.out 3.0

```

I need it to print out

```
"3.0 is a double"

```

However right now it becomes

```
"3 is an int." 

```

What would be a way to check for this? I did look around for similar problems which led me to the current solution but just this one edge case I do not know how to account for.

Thank you.

Answer: 
For example, a way like this:

```
#include <stdio.h>

int main(int argc, char *argv[]){
    if(argc != 2){
        puts("Need an argument!");
        return -1;
    }

    int int_v, read_len = 0;
    double double_v;
    printf("'%s' is ", argv[1]);
    //==1 : It was able to read normally.
    //!argv[1][read_len] : It used all the argument strings.
    if(sscanf(argv[1], "%d%n", &int_v, &read_len) == 1 && !argv[1][read_len])
        puts("an int.");
    else if(sscanf(argv[1], "%lf%n", &double_v, &read_len) == 1 && !argv[1][read_len])
        puts("a double.");
    else
        puts("isn't the expected input.");
}

```
```
int main (int argc,char *argv[])
{
    if(argc==2)
    {
        int i;
        double d;
        d=atof(argv[1]);
        i=atoi(argv[1]);
        if(d!=i)
            printf("%s is a double.",argv[1]);
        else if(d==i)
            printf("%s is an int.",argv[1]);

    }
    else
        printf("Invalid input\n");
    return 0;
}

```

You must add `#include <stdlib.h>`