sábado, 7 de julio de 2012

Validation Character for Peruvian DNI - 2

Following is the function that receives an eight character string, the DNI, and returns the validation character. The C++ code is published at GitHub and can be downloaded here.
char alphaValidationCharacter(char *DNI)
{

  const char serie[] = "89456789";
  char const *t = serie;

  char *s = DNI;

  int sum = 0, partial = 0;

  while(*s!='\0')
  {
    partial = (*s-'0')* (*t-'0');
    sum += partial;
    s++;
    t++;
  }

  int modulus = 0;
  modulus = sum % 11;
  
  return 'A' + (modulus==0?11:modulus) - 1;

} 
The complete project can be downloaded from here

No hay comentarios:

Publicar un comentario en la entrada