Question: Getting a weird segmentation fault on following code when I try to pass a number into my application on command line.

```
int offset = 3;

int main(int argc, char *argv[]) {
    // Check for arguments to see whether there is a custom offset
    if (argc == 2) {
        // If argc == 2 then we have a offset?
        if (isdigit((unsigned char)*argv[1])) {
            offset = atoi(*argv[1]);
            printf("Offset changed to: %d\n", offset);
        } else {
            printf("Offset not changed due to %s not being a number.\n", *argv[1]);
        }
    } else if(argc >= 2) {
        // If argc >= 2 then we have too many arguments
        printf("Too many arguments.");
        return 0;
    }
}

```

Answer: 
The *real* problem with your code is that you are trying to call functions that you didn't declare (you must be using a C89/90 compiler). You call `isdigit`. You call `printf`. You call `atoi`. You call the latter two incorrectly. And the only reason the compiler cannot inform you about these functions being called incorrectly is that you forgot to declare them.

Include `<ctype.h>`, `<stdlib.h>` and `<stdio.h>` at the beginning of your source file, so that the compiler knows the proper parameter types for `atoi` and other functions. Once you do that, you should be able to figure out the problem with the `atoi`, because the compiler will issue a diagnostic message explaining the problem. Then you can change the call accordingly. Some compilers will be able to detect the problem with `printf` call as well.

Note, that even if you change the `atoi` and `printf` calls as recommended in other answers (i.e. to `atoi(argv[1])` etc.), your code will still remain invalid, because in C89/90 calling `printf` without declaring it first leads to undefined behavior (and in C99 it is flat-out illegal to call *any* function without declaring it first).
```
#include <ctype.h>
int isdigit(int c);

```

**isdigit()** expects single char to check, **argv[]** is a pointer to string (array of chars).
Long story short, it won't check strings like **"1234"**, but it will check **'1'**.