本文介绍了我怎样才能改变C中的数组的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用游戏工作室一点点。
我现在想提出一个射击游戏。
我有一个指针对敌人的数组。我想要。当敌人被杀害。从列表中删除他。而且我也希望能够创造新的敌人。

I am experimenting a little bit with gamestudio.I am making now a shooter game.I have an array with the pointer's to the enemies. I want. to when an enemy is killed. remove him from the list. And I also want to be able to create new enemies.

游戏工作室使用名为精简版-C的脚本语言。它具有相同的语法为C,他们说在网站上,它可以与任何C编译器编译。它是纯C,没有C ++或其他任何东西。

Gamestudio uses a scripting language named lite-C. It has the same syntax as C and on the website they say, that it can be compiled with any C compiler. It is pure C, no C++ or anything else.

我是新来C.我通常程序.NET语言和一些脚本语言,

I am new to C. I normally program in .NET languages and some scripting languages,

推荐答案

您不能。这通常与动态内存分配完成的。

You can't. This is normally done with dynamic memory allocation.

// Like "ENEMY enemies[100]", but from the heap
ENEMY* enemies = malloc(100 * sizeof(ENEMY));

// You can index pointers just like arrays.
enemies[0] = CreateEnemy();

// Make the array bigger
enemies = realloc(enemies, 200 * sizeof(ENEMY));

// Clean up when you're done.
free(enemies);

这篇关于我怎样才能改变C中的数组的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 18:40