diff options
| author | zachir <zachir@librem.one> | 2024-03-11 02:00:31 -0500 | 
|---|---|---|
| committer | zachir <zachir@librem.one> | 2024-03-11 02:00:31 -0500 | 
| commit | 3d95ee49b4e45c11d0a9d6368ea3ec6808006a35 (patch) | |
| tree | 43dea24fe43c9b8affadf1e3493501bfe39c130d | |
| parent | 45933ed41766da5e08b59f970ff58df63eb18c8b (diff) | |
Non-numbers that are passed will return -1, and print an error message.
This includes decimal places, as only integers can be even or odd.
| -rw-r--r-- | src/main.c | 8 | 
1 files changed, 6 insertions, 2 deletions
| @@ -35,7 +35,7 @@ int main(int argc, char **argv) {    quiet = false;    value = false;    result = 0; -  char *output; +  char *end = NULL;    if (argc > 1) {      for (int i = 1; i < argc; i++) { @@ -55,7 +55,11 @@ int main(int argc, char **argv) {              break;          }        } -      result = strtol(argv[i], &output, 10); +      result = strtol(argv[i], &end, 10); +      if ((end == argv[i]) || (end[0] != '\0')) { +        fprintf(stderr, "Please provide an integer, not %s!\n", argv[i]); +        return ERR; +      }        value = true;      }    } else { | 
