/usr/include/eancheck.h is in eancheck 1.0-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | #include <iostream.h>
#include <stdlib.h>
#include <string.h>
int ec_checkean(char inputean[])
{
int trip = 0;
for (int c = 0; c < strlen(inputean); c++)
{
if ((inputean[c] < 48) || (inputean[c] > 57))
trip++;
}
if (trip == 0)
{
// the variable for the numbers passed to the function
int digits[strlen(inputean)];
for (int i=0; i < strlen(inputean); i++)
{
// this makes each digit of the EAN a string (with terminating
// character) so that atoi can work its magic on it.
char convert[2];
convert[0] = inputean[i];
convert[1] = '\0';
// converts the char (as sent as argument) into a number.
digits[i] = atoi(convert);
}
// the total of all the "odd" numbers.
int oaccumulator = 0;
// the total of all the "even" numbers.
int eaccumulator = 0;
for (int o=0; o<strlen(inputean)-1; o=o+2)
{
oaccumulator = oaccumulator + digits[o];
}
for (int e=1; e<strlen(inputean)-1; e=e+2)
{
eaccumulator = eaccumulator + digits[e];
}
short int cdigit;
cdigit = 10 - (((eaccumulator * 3) + oaccumulator) % 10);
if (cdigit == 10) cdigit = 0;
if (cdigit == digits[strlen(inputean)-1])
{
return 0;
} else {
return 1;
}
} else {
return 3;
}
}
int ec_gencd(char inputean[])
{
int trip = 0;
for (int c = 0; c < strlen(inputean); c++)
{
if ((inputean[c] < 48) || (inputean[c] > 57))
trip++;
}
if (trip == 0)
{
// the variable for the numbers passed to the function
int digits[strlen(inputean)];
for (int i=0; i < strlen(inputean); i++)
{
// this makes each digit of the EAN a string (with terminating
// character) so that atoi can work its magic on it.
char convert[2];
convert[0] = inputean[i];
convert[1] = '\0';
// converts the char (as sent as argument) into a number.
digits[i] = atoi(convert);
}
// the total of all the "odd" numbers.
int oaccumulator = 0;
// the total of all the "even" numbers.
int eaccumulator = 0;
for (int o=0; o<strlen(inputean); o=o+2)
{
oaccumulator = oaccumulator + digits[o];
}
for (int e=1; e<strlen(inputean); e=e+2)
{
eaccumulator = eaccumulator + digits[e];
}
short int cdigit;
cdigit = 10 - (((eaccumulator * 3) + oaccumulator) % 10);
if (cdigit == 10) cdigit = 0;
return cdigit;
} else {
return 10;
}
}
|