2014-11-29 3 views
1

라즈베리 파이의 지문 판독기에 액세스하려고합니다. 나는 "Adafruit Fingerprint Sensor Library"을 기반으로 도서관을 썼다. 여기 내 예제 코드입니다 :할당없이 포인터가 바뀝니다

int main(int argc, char **argv) 
{ 
    int res = wiringPiSetup(); 
    if (res == -1) 
    { 
     perror("wiringPiSetup"); 
     return EXIT_FAILURE; 
    } 

    /* malloc fingerprint_t */ 
    fingerprint_t *fp = fingerprint_init(argv[1], atoi(argv[2])); 

    /* this call to fingerprint sensor works fine */ 
    if (fingerprint_verify_password(fp)) 
    { 
     printf("Found fingerprint sensor\n"); 
    } 
    else 
    { 
     printf("Did not find fingerprint sensor\n"); 
     return EXIT_FAILURE; 
    } 

    /* fp pointer is 0x12008 here */ 

    while(true) 
    { 
     uint8_t id; 
     printf("type in the ID # you want to save finger print:"); 
     scanf("%u", &id); 
     printf("Enrolling ID #%u\n", id); 

     /* same fp pointer is 0x10000 here */ 

     while (true) 
     { 
      /* Program received signal SIGSEGV, Segmentation fault inside this function */ 
      uint8_t res = get_fingerprint_enroll(fp, id); 
      if (!res) 
      { 
       printf("*****************\n"); 
       break; 
      } 
     } 
    } 
} 

fp 포인터가 처음 while 루프 전에 OK이지만 get_fingerprint_enroll에서 프로그램에 SIGSEGV의 원인이 할당하지 않고 두 번째 while 전에 변경합니다. fingerprint_t 구조체는 다음과 같이이다 :

typedef struct _fingerprint_t 
{ 
    uint16_t finger_id; 
    uint16_t confidence; 
    uint16_t template_count; 
    uint32_t password; 
    uint32_t address; 
    uint32_t fd; 
} fingerprint_t; 

이 같은 fingerprint_initfp 메모리를 할당 : 만 fingerprint_init 내부 password, addressfd를 초기화

fingerprint_t *fp = (fingerprint_t *) malloc(sizeof(fingerprint_t)); 

. 내가 뭘 잘못하고있어? id 같은 scanf("%u", &id);에서

답변

4

은, IMO, 당신은 scanf(" %c", &id);를 작성해야 [보통 unsigned char로 표현되는] uint8_t이다.

%uunsigned int을 나타냅니다.

같음 printf("Enrolling ID #%u\n", id);