|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD_WEIGHT_6 "65432"
#define MOD_WEIGHT_5 "5432"
#define SUCCESS 1
#define ERROR 0
int checkSum
(char *value);
int main (int
argc, char *argv[])
{ if (argc == 2)
{ if(!checkSum(argv[1]))
printf("Number
incorrect length (4-5 digits only)\n");
}else
{ printf("Please
enter a number with the checkdigit missing:\n");
printf("
1234 = 5th digit will be the checkdigit\n");
printf("
12345 = 6th digit will be the checkdigit\n");
}
return EXIT_SUCCESS;
}
int checkSum
(char *value)
{ int count;
int temp=0;
int x;
count=strlen(value);
for (x=0; x < count; x++)
if (count ==
4)
temp+=((value[x] -48) * (MOD_WEIGHT_5[x]-48));
else if (count
== 5)
temp+=((value[x] -48) * (MOD_WEIGHT_6[x]-48));
else
return ERROR;
count = (11-(temp%11));
printf("Number with checkdigit appended = %s",value);
if (count == 11)
printf("X\n");
else if (count == 10)
printf("0\n");
else
printf("%d\n",count);
return SUCCESS;
}
|