0

在此处输入图像描述

大家好,来自上图。我能够编译,但程序在运行时崩溃。请告诉我解决这个问题的解决方案是什么?谢谢

// 结构数组.h:

 #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;
}
4

2 回答 2

4

您正在访问t[1],但在 中只有一项t。试试printf("Content: \n%x \n", t[0].str[1])

于 2013-09-21T08:36:15.977 回答
3

数组索引在 C 中从 0 开始。您正在访问数组末尾之后的数组元素。将索引更改为 0:

printf("Content: \n%x \n", t[0].str[0]); 
于 2013-09-21T08:37:48.153 回答