#### Archived

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

# 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)
{

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

SetFilePointer(hFile,0,0,FILE_BEGIN);

//(insert removed code here) :P

CloseHandle(hFile);
}
}

ill give you 110010 dollars for your car

##### 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 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

• ### Forum Statistics

• Total Topics
628368
• Total Posts
2982293

• 10
• 9
• 13
• 24
• 11