2013-09-21 1 views
0

enter image description here구조체 배열 버그

안녕 모두, 위의 이미지에서 . 컴파일 할 수 있지만 런타임에 프로그램이 중단됩니다. 이 문제를 해결할 수있는 해결책을 알려주십시오. 는 감사

// structArray.h : 당신은 t[1]에 접속 만 t 하나 개의 항목이 있습니다

#ifndef __STRUCTARRAY_H_ 
#define __STRUCTARRAY_H_ 


typedef struct _vector{ 
    int* str; 
    int  maskSize; 
    // etc... 
}__attribute__((__packed__)) _vector_t; 

#endif /* _STRUCTARRAY_H_ */ 

**// do_structArray.c** 

#include "structArray.h" 

extern struct _vector_t t; 

void do_structArray (void) { 

int plaintext[2] = {0x05, 0x08}; 

_vector_t t[] = { 
    {plaintext, sizeof(plaintext)}, 
    //{}, 
}; 

    printf("Content: \n%x \n", t[1].str[1]); 
} 

// main : just calling do_structArray 
#include <stdio.h> 
#include <stdlib.h> 

#include "structArray.h" 

extern struct _vector_t t; 

int main(int argc, char *argv[]) {  
do_structArray(); 

    system("PAUSE"); 
    return 0; 
} 

답변

3

배열 색인은 C에서 0부터 시작합니다. 배열 끝을 지나서 배열 요소에 액세스하고 있습니다. 색인을 0으로 변경하십시오.

printf("Content: \n%x \n", t[0].str[0]); 
+0

죄송합니다. 늦은 밤의 프로그래밍이 내게 정말로 들어 있습니다. 이 말이 맞습니다. 도와 주셔서 감사합니다. –

4

. printf("Content: \n%x \n", t[0].str[1])을 시도하십시오.

+0

감사합니다. 나는 그것을 지금 본다. –