Archived

This topic is now archived and is closed to further replies.

maxushax

Char Arrays and Createfile()

Recommended Posts

the purpose of this function is to accept input like "jump.ani,fly.ani" and load each one into an array of a struct ive made. here is my problem: during the first ''while (x==0)'' filename is loaded with ''jump.ani'' and it loads ther file correctly. the second time, though, the correct character from strAnim is found during debug, but it doesnt actually put that char into filename, even though it goes over ''filename[z]=strAnims[z];''.. anyone know what im doing wrong? thanks for any input
void readanimations(char *strAnims)
{
int i,x,y,z;long lAnimCount=0;char filename[256];DWORD dwBytesRead=0;DWORD dwFilesRead=0;

	i=x=y=z=0;
	long lAnimSize=strlen(strAnims);

	for (i=0;i<lAnimSize;i++)
	{
		if (strAnims[i]==0x2C)
		lAnimCount++;
	}
	if (lAnimCount!=-1)
		lAnimCount++;

	animations=(Anim*)malloc(sizeof(Anim)*lAnimCount);

	for (i=0;i<lAnimCount;i++)
	{
		memset(filename,0,256);

		x=0;
		while (x==0)
		{
		if (strAnims[z]!=0x2C)
		{
			filename[z]=strAnims[z];
			z++;
		}
		else
		{
			z++;
			x=1;
		}
		}

		HANDLE hFile=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
		SetFilePointer(hFile,0,0,FILE_BEGIN);

		//(insert removed code here) :P


		CloseHandle(hFile);
	}
}
ill give you 110010 dollars for your car

Share this post


Link to post
Share on other sites
I believe the problem is in the line filename[z]=strAnims[z];

You should use a different index for filename that restarts at 0 each time through the loop. Currently lets say after the first loop z = 5, then at the beginning of the second loop it will set filename[5]=strAnims[5]. This causes a problem because filename[0] = 0 which is the null terminator.

Share this post


Link to post
Share on other sites
lol i completely forgot :X .. thanks a lot though, maybe now i can actually get my game started (this is one of the final aspects of the engine)

ill give you 110010 dollars for your car

Share this post


Link to post
Share on other sites