Game Development Reference
function fails to read a full zero terminated string then it returns false. This
can be because of either a file read error or because the length of the
buffer passed to the function was insufficient to store the string being
read. The function returns the read string in the character buffer 'buf'. If
the size of a string is odd then we need to read another byte from the file,
since all strings start on an even byte boundary.
BOOL CLWObject::ReadString(FILE *fp, char *buf, int &count,
count = 0;
if (fread(&buf[count], 1, 1, fp)!=1) return FALSE;
if (buf[count++]==0) break;
if (count==buflength) return FALSE;
//Align to even byte boundary
if (count%2) fseek(fp, 1, SEEK_CUR);
//Don't include final zero in count
To read the tag chunk simply call ReadString repeatedly until the length
of the chunk is reached. The length of the string is returned in the passed
count variable. Store all the strings in an array. They will be needed when
reading a surface chunk.
Reading a layer section
The content of a layer is finished when the end of a file is reached or
another LAYR chunk is found. Let's examine a simple unit cube file to see
how the data for a layer are stored.
FORM 340 LWO2
TAGS 8 "Default"
0 0 0.0 0.0 0.0 ""
-0.5 -0.5 -0.5
0.5 -0.5 -0.5