corriger fonction code128( pour code barre Code128)
Bonjour,
s'il vous plait, je voudrais une aide,
j'ai téléchargé la fonction de transformation d'une chaine de caractère en une chaine code128 sur le site de grandzebu, mais cette fonction ne me renvoie pas une bonne chaine de caractère, je voudrais que quelqu'un me regarde le code ci-dessous et me dise ou ça cloche. Moi j'ai déjà cherché en vain. Ou bien si quelqu'un a une telle fonction déjà prête qu'il veuille bien me la proposer.
actuellement par exemple,
Citation:
ChaineAEncoder="2007A0015", ChaineResultat="210"
ChaineAEncoder="2007A0455", ChaineResultat="210"
c'est absurde.
Voici ci-dessous la fonction en question
Code:
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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
| *** Parameters / Paramètres ***
BufIn : Pointer to a string to convert / Pointeur sur une chaine à convertir
SizeIn : Length of the BufIn string / Longueur de la chaine BufIn
BufOut : Pointer to the result string / Pointeur sur la chaine résultat
SizeOut : Pointer to the length of the result string / Pointeur sur la longueur de la chaine résultat
*** Return values / Valeur de retour ***
-1 : Buffer for output string too small - Give to the buffer the size SizeOut and call again the function / Tampon pour la chaine de sortie trop petit - Donner au tampon la taille SizeOut et rappeler la fonction
0 : No error / Pas d'erreur
1 : Input string not allowed / Chaine d'entrée non permise
long __stdcall Code128(char *BufIn, long SizeIn, long *SizeOut, unsigned char *BufOut)
{
int i;
long j;
char x;
int checksum;
long mini;
long dummy;
bool tableB;
if (SizeIn > 0)
{
//Vérifier si caractères valides
//Check for valid characters
for (i = 0; i < SizeIn; i++)
{
x = *(BufIn + i);
if ((x < 32 || x > 126) && x != 203) return 1;
}
//Calculer la chaine de code en optimisant l'usage des tables B et C
//Calculation of the code string with optimized use of tables B and C
tableB = true;
i = 0; //i devient l'index sur la chaine d'entrée / i become the input string index
j = 0; //j est l'index sur la chaine de sortie / j is the output string index
while (i < SizeIn)
{
if (tableB)
{
//Voir si intéressant de passer en table C / See if interesting to switch to table C
//Oui pour 4 chiffres au début ou à la fin, sinon pour 6 chiffres / yes for 4 digits at start or end, else if 6 digits
mini = (i == 0 || i + 4 == SizeIn) ? 3 : 5;
if (i + mini < SizeIn)
{
while (mini >= 0)
{
if (*(BufIn + i + mini) < 48 || *(BufIn + i + mini) > 57) break;
mini--;
}
}
//si les mini% caractères à partir de i% sont numériques, alors mini%=-1
//if the mini% characters from i% are numeric, then mini%=-1
if (mini < 0)
{ //Choix table C / Choice of table C
if (i == 0)
{ //Débuter sur table C / Starting with table C
if (j < *SizeOut)
*(BufOut + j) = 210;
}
else
{ //Commuter sur table C / Switch to table C
if (j < *SizeOut)
*(BufOut + j) = 204;
}
j++;
tableB = false;
}
else
{
if (i == 0)
{
if (j < *SizeOut) *(BufOut + j) = 209; //Débuter sur table B / Starting with table B
j++;
}
}
}
if (! tableB)
{
//On est sur la table C, essayer de traiter 2 chiffres / We are on table C, try to process 2 digits
mini = 1;
if (i + mini < SizeIn)
{
while (mini >= 0)
{
if (*(BufIn + i + mini) < 48 || *(BufIn + i + mini) > 57) break;
mini--;
}
}
//si les mini% caractères à partir de i% sont numériques, alors mini%=-1
//if the mini% characters from i% are numeric, then mini%=-1
if (mini < 0)
{ //OK pour 2 chiffres, les traiter / OK for 2 digits, process it
dummy = (*(BufIn + i) - 48) * 10 + *(BufIn + i + 1) - 48;
if (j < *SizeOut) *(BufOut + j) = (dummy < 95) ? dummy + 32 : dummy + 105;
i = i + 2;
}
else
{ //On n'a pas 2 chiffres, repasser en table B / We haven't 2 digits, switch to table B
if (j < *SizeOut) *(BufOut + j) = 205;
tableB = true;
}
j++;
}
if (tableB)
{
//Traiter 1 caractère en table B / Process 1 digit with table B
if (j < *SizeOut) *(BufOut + j) = *(BufIn + i);
j++;
i++;
}
}
//Calcul de la clé de contrôle / Calculation of the checksum
for (i = 0; i < j; i++)
{
dummy = *(BufOut + i);
dummy = (dummy < 127) ? dummy - 32 : dummy - 105;
if (i == 0) checksum = dummy;
checksum = (checksum + i * dummy) % 103;
}
//Calcul du code ASCII de la clé / Calculation of the checksum ASCII code
checksum = (checksum < 95) ? checksum + 32 : checksum + 105;
//Ajout de la clé et du STOP / Add the checksum and the STOP
if (j < *SizeOut) *(BufOut + j) = checksum;
j++;
if (j < *SizeOut) *(BufOut + j) = 211;
j++;
if (j > *SizeOut)
{
*SizeOut = j;
return -1;
}
else
{
*SizeOut = j;
return 0;
}
}
else
{
return 1;
}
} |