/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

static int isint(const char *s)
{
    int res, i;
    if((s == NULL) || (strlen(s) == 0))
    {
        res = FALSE;
    }
    else
    {
        res = TRUE;
        for(i = 0; i < strlen(s); i++)
        {
            if((s[i] < '0') || ('9' < s[i]))
            {
                if((i != 0) || (s[i] != '-'))
                {
                    res = FALSE;
                }
            }
        }
    }
    return res;
}

static int isintx(const char *s)
{
    int res, i;
    if((s == NULL) || (strlen(s) == 0))
    {
        res = FALSE;
    }
    else
    {
        res = TRUE;
        for(i = 0; i < strlen(s); i++)
        {
            if((s[i] < 48) || (57 < s[i]))
            {
                if((i != 0) || (s[i] != 45))
                {
                    res = FALSE;
                }
            }
        }
    }
    return res;
}

static void test(const char *s)
{
    printf("\"%s\" : %d\n", s, isint(s));
    printf("\"%s\" : %d\n", s, isintx(s));
}

int main(int argc, char *argv[])
{
    test("123");
    test("-123");
    test("ABC");
    test("123X");
    test("");
    return 0;
}
