I'm not all that familiar with the C syntax rules, I've mostly worked with C++, and I'm having some weird problems working with Visual C 2008. Here's my code:

#ifndef IFF_H
#define IFF_H

#include <stdio.h>
#include <stdlib.h>

#define IDS_GROUP ""
#define IDN_GROUP 1
#define IDS_CAT "cat "
#define IDN_CAT 2
#define IDS_LIST "list"
#define IDN_LIST 4
#define IDS_PROP "prop"
#define IDN_PROP 8
#define IDS_FORM "form"
#define IDN_FORM 16
#define IDS_RIFF "riff"
#define IDN_RIFF 32

typedef struct GROUP *GROUP;
typedef struct CHUNK *CHUNK;

struct CHUNK
{
	//GROUP *__parent;
	char *chunkID;
	unsigned long size;
	char *data;
};

struct GROUP
{
	GROUP *__parent;
	char *typeID;
	unsigned long remainingSize;
	char *groupID;
	GROUP *cats;
	int nCats;
	GROUP *lists;
	int nLists;
	GROUP *props;
	int nProps;
	GROUP *forms;
	int nForms;
	CHUNK *chunks;
	int nChunks;
};

void groupCon(GROUP *group);
void groupDes(GROUP *group);
void chunkCon(CHUNK *chunk);
void chunkDes(CHUNK *chunk);

void groupCon(GROUP *group)
{
	group->__parent = NULL;
	group->typeID = (char *)malloc(4);
	group->remainingSize = 0;
	group->typeID = (char *)malloc(4);
	group->cats = (GROUP *)malloc(0);
	group->nCats = 0;
	group->lists = (GROUP *)malloc(0);
	group->nLists = 0;
	group->props = (GROUP *)malloc(0);
	group->nProps = 0;
	group->forms = (GROUP *)malloc(0);
	group->nForms = 0;
	group->chunks = (CHUNK *)malloc(0);
	group->nChunks = 0;
}

void groupDes(GROUP *group)
{
	int i;
	for(i = 0; i < sizeof(group->cats) / sizeof(GROUP); i++)
	{
		groupDes(&group->cats[i]);
	}
	for(i = 0; i < sizeof(group->lists) / sizeof(GROUP); i++)
	{
		groupDes(&group->lists[i]);
	}
	for(i = 0; i < sizeof(group->props) / sizeof(GROUP); i++)
	{
		groupDes(&group->props[i]);
	}
	for(i = 0; i < sizeof(group->forms) / sizeof(GROUP); i++)
	{
		groupDes(&group->forms[i]);
	}
	for(i = 0; i < sizeof(group->chunks) / sizeof(GROUP); i++)
	{
		chunkDes(&group->chunks[i]);
	}

	free(group->cats);
	free(group->lists);
	free(group->props);
	free(group->forms);
	free(group->chunks);
}

void chunkCon(CHUNK *chunk)
{
	//chunk->__parent = NULL;
	chunk->chunkID = (char *)malloc(4);
	chunk->size = 0;
	chunk->data = (char *)malloc(0);
}

void chunkDes(CHUNK *chunk)
{
	free(chunk->chunkID);
	free(chunk->data);
}

int strCmp(char *str1, char *str2)
{
	int i;

	for(i = 0; i < sizeof(str1) || i < sizeof(str2); i++)
	{
		if(i < sizeof(str1) && i < sizeof(str2))
		{
			if(str1[i] > str2[i])
			{
				return i;
			}
			else if(str2[i] > str1[i])
			{
				return -i;
			}
		}
		else if(i < sizeof(str1))
		{
			return i;
		}
		else if(i < sizeof(str2))
		{
			return -i;
		}
	}

	return 0;
}

bool readIFFfile(char *filename, GROUP *super)
{
	char *typeIDs[] = {IDS_CAT, IDS_LIST, IDS_PROP, IDS_FORM, IDS_RIFF};
	int typeIDn[] = {IDN_CAT, IDN_LIST, IDN_PROP, IDN_FORM, IDN_RIFF};
	char buffer[4];
	FILE *fp;
	GROUP *current = NULL;
	bool success = true;
	int i;
	bool bigEndian = true;

	fp = fopen(filename, "rb");
	if(!fp)
	{
		return NULL;
	}
	while(!feof(fp))
	{
		// typeID (or chunkID)
		if(fread(buffer, 1, 4, fp) != 4)
		{
			if(ferror(fp))
			{
				perror("Error occurred reading iff file: ");
				success = false;
				break;
			}
			else
			{
				fputs("Error occurred reading iff file: file ended unexpectedly", stderr);
				success = false;
				break;
			}
		}

		for(i = 0; i < sizeof(typeIDs) / 4; i++)
		{
			if(strCmp(typeIDs[i], buffer) == 0) // is a valid type ID
			{
				if(current == NULL)
				{
					current = super; // we should use the user-supplied group
					groupCon(current); // initialize the group
				}
				else
				{
					switch(typeIDn[i]) // adds a new group of the proper type
					{
						case IDN_CAT:
						{
							realloc(current->cats, ++current->nCats * sizeof(GROUP));
							current = &current->cats[current->nCats - 1];
						} break;
						case IDN_LIST:
						{
							realloc(current->lists, ++current->nLists * sizeof(GROUP));
							current = &current->lists[current->nLists - 1];
						} break;
						case IDN_PROP:
						{
							realloc(current->props, ++current->nProps * sizeof(GROUP));
							current = &current->props[current->nProps - 1];
						} break;
						case IDN_FORM:
						{
							realloc(current->forms, ++current->nForms * sizeof(GROUP));
							current = &current->forms[current->nForms - 1];
						} break;
						case IDN_RIFF:
						{
							realloc(current->forms, ++current->nForms * sizeof(GROUP));
							current = &current->forms[current->nForms - 1];
							bigEndian = false;
						} break;
					}
				}
			}
			else if(i == (sizeof(typeIDs) / 4) - 1) // didn't match any IDs, is a chunk
			{
				realloc(current->chunks, ++current->nChunks * sizeof(CHUNK));
			}
		}
	}

	return success;
}

#endif

And here are the errors Visual C gives me:

------ Build started: Project: IFF, Configuration: Debug Win32 ------
Compiling...
Main.c
f:\programming\projects\c++\iff\iff.h(58) : error C2223: left of '->__parent' must point to struct/union
f:\programming\projects\c++\iff\iff.h(59) : error C2223: left of '->typeID' must point to struct/union
f:\programming\projects\c++\iff\iff.h(60) : error C2223: left of '->remainingSize' must point to struct/union
f:\programming\projects\c++\iff\iff.h(61) : error C2223: left of '->typeID' must point to struct/union
f:\programming\projects\c++\iff\iff.h(62) : error C2223: left of '->cats' must point to struct/union
f:\programming\projects\c++\iff\iff.h(63) : error C2223: left of '->nCats' must point to struct/union
f:\programming\projects\c++\iff\iff.h(64) : error C2223: left of '->lists' must point to struct/union
f:\programming\projects\c++\iff\iff.h(65) : error C2223: left of '->nLists' must point to struct/union
f:\programming\projects\c++\iff\iff.h(66) : error C2223: left of '->props' must point to struct/union
f:\programming\projects\c++\iff\iff.h(67) : error C2223: left of '->nProps' must point to struct/union
f:\programming\projects\c++\iff\iff.h(68) : error C2223: left of '->forms' must point to struct/union
f:\programming\projects\c++\iff\iff.h(69) : error C2223: left of '->nForms' must point to struct/union
f:\programming\projects\c++\iff\iff.h(70) : error C2223: left of '->chunks' must point to struct/union
f:\programming\projects\c++\iff\iff.h(71) : error C2223: left of '->nChunks' must point to struct/union
f:\programming\projects\c++\iff\iff.h(77) : error C2223: left of '->cats' must point to struct/union
f:\programming\projects\c++\iff\iff.h(79) : error C2223: left of '->cats' must point to struct/union
f:\programming\projects\c++\iff\iff.h(79) : error C2198: 'groupDes' : too few arguments for call
f:\programming\projects\c++\iff\iff.h(81) : error C2223: left of '->lists' must point to struct/union
f:\programming\projects\c++\iff\iff.h(83) : error C2223: left of '->lists' must point to struct/union
f:\programming\projects\c++\iff\iff.h(83) : error C2198: 'groupDes' : too few arguments for call
f:\programming\projects\c++\iff\iff.h(85) : error C2223: left of '->props' must point to struct/union
f:\programming\projects\c++\iff\iff.h(87) : error C2223: left of '->props' must point to struct/union
f:\programming\projects\c++\iff\iff.h(87) : error C2198: 'groupDes' : too few arguments for call
f:\programming\projects\c++\iff\iff.h(89) : error C2223: left of '->forms' must point to struct/union
f:\programming\projects\c++\iff\iff.h(91) : error C2223: left of '->forms' must point to struct/union
f:\programming\projects\c++\iff\iff.h(91) : error C2198: 'groupDes' : too few arguments for call
f:\programming\projects\c++\iff\iff.h(93) : error C2223: left of '->chunks' must point to struct/union
f:\programming\projects\c++\iff\iff.h(95) : error C2223: left of '->chunks' must point to struct/union
f:\programming\projects\c++\iff\iff.h(95) : error C2198: 'chunkDes' : too few arguments for call
f:\programming\projects\c++\iff\iff.h(98) : error C2223: left of '->cats' must point to struct/union
f:\programming\projects\c++\iff\iff.h(98) : error C2198: 'free' : too few arguments for call
f:\programming\projects\c++\iff\iff.h(99) : error C2223: left of '->lists' must point to struct/union
f:\programming\projects\c++\iff\iff.h(99) : error C2198: 'free' : too few arguments for call
f:\programming\projects\c++\iff\iff.h(100) : error C2223: left of '->props' must point to struct/union
f:\programming\projects\c++\iff\iff.h(100) : error C2198: 'free' : too few arguments for call
f:\programming\projects\c++\iff\iff.h(101) : error C2223: left of '->forms' must point to struct/union
f:\programming\projects\c++\iff\iff.h(101) : error C2198: 'free' : too few arguments for call
f:\programming\projects\c++\iff\iff.h(102) : error C2223: left of '->chunks' must point to struct/union
f:\programming\projects\c++\iff\iff.h(102) : error C2198: 'free' : too few arguments for call
f:\programming\projects\c++\iff\iff.h(108) : error C2223: left of '->chunkID' must point to struct/union
f:\programming\projects\c++\iff\iff.h(109) : error C2223: left of '->size' must point to struct/union
f:\programming\projects\c++\iff\iff.h(110) : error C2223: left of '->data' must point to struct/union
f:\programming\projects\c++\iff\iff.h(115) : error C2223: left of '->chunkID' must point to struct/union
f:\programming\projects\c++\iff\iff.h(115) : error C2198: 'free' : too few arguments for call
f:\programming\projects\c++\iff\iff.h(116) : error C2223: left of '->data' must point to struct/union
f:\programming\projects\c++\iff\iff.h(116) : error C2198: 'free' : too few arguments for call
f:\programming\projects\c++\iff\iff.h(149) : error C2061: syntax error : identifier 'readIFFfile'
f:\programming\projects\c++\iff\iff.h(149) : error C2059: syntax error : ';'
f:\programming\projects\c++\iff\iff.h(149) : error C2059: syntax error : 'type'
f:\programming\projects\c++\iff\main.c(8) : warning C4013: 'readIFFfile' undefined; assuming extern returning int
Build log was saved at "file://f:\Programming\Projects\C++\IFF\Debug\BuildLog.htm"
IFF - 49 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Please don't tell my about how this won't work or any logical errors I've made because this isn't even close to being finished. I would just really appreciate any suggestions on how to fix this. (And yes, I know it would work syntactically if I didn't have the __parent member but then it wouldn't work logically, so I kind of need it).

GROUP *current = NULL;

You have declared this current pointer and you havnt allocated memory for it and again in the groupcon function you are trying to derefrence the null pointer which is an undefined behavior.

Allocate memory in the main and then tru current to the groupcon function. And do the same for all.

And C donst support bool data type. Use macros instead.

ssharish

Possibly...?

typedef struct GROUP GROUP; /* assuming * was erroneous? */
typedef struct CHUNK CHUNK; /* assuming * was erroneous? */
typedef enum {false,true} bool;
commented: That was spot on Dave, I never looked at it at the first instance. +2

Oh, thanks Dave! I wasn't sure about those typedef statements, I actually just saw that type of thing somewhere and copied the idea. Thank you very much.

Well I the current pointer was in main. But it was in a different function and that’s fine. Look at Dave’s post as well. He pick the interesting part. Let your type def be after the struct declaration. And you cant have the same identifiers defined in the type def.

struct GROUP
{
	struct GROUP *__parent;
    struct GROUP *cats;
	char *typeID;
	unsigned long remainingSize;
	char *groupID;
	int nCats;
	struct GROUP *lists;
	int nLists;
	struct GROUP *props;
	int nProps;
	struct GROUP *forms;
	int nForms;
	struct CHUNK *chunks;
	int nChunks;
	
};
typedef struct GROUP *GROU;
typedef struct CHUNK *CHUNK;

Now change all the GROUP references to GROU. And should get ride of quite a lot of error for you.

Ssharish.

Sorry ssharish, Dave posted before I did and I didn't notice it so I edited my post rather than making another. His suggestion fixed my problem.

Actually, C does support boolean values, but you have to declare them with the _Bool operator. However, you can add to the #include block

#include <stdbool.h>

. This will allow you to define booleans with

bool

instead of

_Bool
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.