#include <stdio.h>
int tran_15_to_18( char* cert_no )
{
char resultID[19];
const char Weight[] = { 7, 9, 10, 5, 8, 4, 2, 1, 6 , 3, 7, 9, 10, 5, 8 , 4, 2 };
const char Check[] = { '1', '0' , 'X', '9', '8', '7', '6','5', '4', '3', '2' };
int i, sum, mod;
if (cert_no == NULL)
{
return -1;
}
memset(resultID, 0, sizeof(resultID));
strncpy(resultID, cert_no, 6);
strcat(resultID, "19");
strncat(resultID, cert_no+6, 9);
sum = 0;
for( i = 0 ; i < 17 ; i++)
{
sum += ( resultID[i] - 48 ) * Weight[i];
}
mod = sum % 11;
resultID[17] = Check[mod];
resultID[18] = '\0';
strcpy(cert_no, resultID);
return 0;
}
int main()
{
char p[21] = "320521720807225 ";
puts(p);
tran_15_to_18(p);
puts(p); /* 320521197208072253 */
return 0;
}