History: Array Realloc
Dynamic realloc of an Array
Dynamic resizing of an array / memory.
Code
#include <Windows.h>
#include <malloc.h>

struct OBJECT{
	int x,y,w,h,parrent;
	float angle;
	unsigned char type,arg0;
	bool exists;
};

int _tmain(int argc, _TCHAR* argv[])
{
	OBJECT *Array = (OBJECT*)malloc(sizeof(OBJECT) * 1);

	Array = (OBJECT*)realloc(Array, sizeof(OBJECT) * 20);

	for(int i=0; i<20; i++)
		Array[i].arg0 = i;

	for(int i=0; i<20; i++)
		printf(">%d<\n",Array[i].arg0);

	printf("REALLOC to 40\n");
	Array = (OBJECT*)realloc(Array, sizeof(OBJECT) * 40);

	for(int i=0; i<40; i++)
		Array[i].arg0 = i;

	for(int i=0; i<40; i++)
		printf(">%d<\n",Array[i].arg0);

	free( Array );
	system("pause");
	return 0;
}
Code.Tode.cz by Henry - 2014
Získejte registraci domén s tld .online, .space, .store, .tech zdarma!
Stačí si k jedné z těchto domén vybrat hosting Plus nebo Mega a registraci domény od nás dostanete za 0 Kč!
Objednat