corpnum.exe

 

 

C:

 

// 법인등록번호 검증기
// Corporation registration number validator
#include <stdio.h>
#include <string.h>
#include <malloc.h>
 
int isCRN(char *a) {
  if (strlen(a) != 13) return 0;
  int s = 0, i;
  for (i = 0; i <= 11; i++) {
    s += ((i % 2) + 1) * (a[i]-'0');
  }
  s = (10 - (s % 10)) % 10;
  return s == (a[12]-'0');
}
 
char *readline(char *prompt) {
  size_t size = 80;
  char *str = malloc(sizeof(char) * size);
  int c;
  size_t len = 0;
  printf(prompt);
  while (EOF != (c = getchar()) && c != '\r' && c != '\n') {
    str[len++] = c;
    if(len == size) str = realloc(str, sizeof(char) * (size *= 2));
  }
  str[len++]='\0';
  return realloc(str, sizeof(char) * len);
}
 
int main() {
  puts("Corporation registration number validator");
  for (;;) {
    char *s;
    s = readline("> ");
    if (feof(stdin)) break;
    puts(isCRN(s) ? "true" : "false");
    free(s);
  }
  return 0;
}

 

 

신고
Posted by steloflute


Generate bitcoin for me

What's this?

티스토리 툴바