/* 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 <ctype.h>

static int ix[] = { 0, 1, 2, 3, 4, 5, 7, 8, 9, 10 };
static int c[] = { 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 };

int isvalid(char *number)
{
    int i,d,m,y,temp;
    char buf[3];
    if (strlen(number) != 11)
    {
        return 0;
    }
    if (number[6] != '-')
    {
        return 0;
    }
    for (i = 0; i < 10; i++)
    {
        if (!isdigit(number[ix[i]]))
        {
            return 0;
        }
    }
    strncpy(buf,number,2);
    buf[2]='\0';
    d=atoi(buf);
    strncpy(buf,number+2,2);
    buf[2]='\0';
    m=atoi(buf);
    strncpy(buf,number+4,2);
    buf[2]='\0';
    y=atoi(buf);
    if (d > 31)
    {
        return 0;
    }
    if (m > 12)
    {
         return 0;
    }
    temp=0;
    for (i = 0; i < 10; i++) {
        temp = temp + c[i] * (number[ix[i]] - '0');
    }
    return ((temp % 11) == 0);
}

void test(char *s)
{
    printf("%s -> %d\n",s,isvalid(s));
}

int main()
{
    test("123456-1234");
    test("111111-1118");
    return 0;
}
