小编And*_*rew的帖子

C中的动态内存分配不起作用

我正在尝试在C中创建一个需要动态大小的数组的游戏,但是即使相同的代码在我的另一个程序中工作,我的代码也无法运行.

这是我的 #includes

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SwinGame.h" //API for graphics, physics etc
#include <math.h>
Run Code Online (Sandbox Code Playgroud)

以下是我typedefs使用的相关内容structs:

typedef struct position_data
{
  double x;
  double y;
} position_data;

typedef enum enemy_type_data {CIRCLE, TRIANGLE, SQUARE} enemy_type_data;

typedef struct enemy_data
{
  position_data location;
  enemy_type_data type;
  bitmap bmp;
  double health;
  double speed;
  int path_to;
} enemy_data;

typedef struct enemy_data_array
{
  int size;
  enemy_data *data;
} enemy_data_array;
Run Code Online (Sandbox Code Playgroud)

这是向元素添加元素的函数:

void add_enemy(enemy_data_array *enemies)
{
  enemy_data *new_array;
  enemies->size++;
  new_array = (enemy_data *)realloc(enemies->data, …
Run Code Online (Sandbox Code Playgroud)

c struct

3
推荐指数
1
解决办法
106
查看次数

标签 统计

c ×1

struct ×1