Sign in to follow this  

cut large code to smaller code

This topic is 3739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using C and windows, i have the following code , this is just a snipit there is loads more all in the same format, can i make a function to handle all this
		name = pVehicleData->pCarInfo[pEntrantData->pEntrants[i].chassis].name;
		for(j = 0; j < gNumberOfChassis; j++)
		{
			if (name == gStringTable[ST_Chassis+j])
			{
				goto donechassis;

			}
		}
		gStringTable[ST_Chassis+gNumberOfChassis] = name;
		Chassis2ChassisIdMap[gNumberOfChassis] = pEntrantData->pEntrants[i].chassis;
		gNumberOfChassis++;
donechassis:

		name = pVehicleData->pEngineInfo[pEntrantData->pEntrants[i].engine].name;
		for(j = 0; j < gNumberOfEngines; j++)
		{
			if (name == gStringTable[ST_Engines+j])
			{
				goto doneengine;
			}
		}
		gStringTable[ST_Engines+gNumberOfEngines] = name;
		Engine2EngineIdMap[gNumberOfEngines] = pEntrantData->pEntrants[i].engine;
		gNumberOfEngines++;
doneengine:


		name = pVehicleData->pTyreInfo[pEntrantData->pEntrants[i].tyre].name;
		for(j = 0; j < gNumberOfTyres; j++)
		{
			if (name == gStringTable[ST_Tyres+j])
			{
				goto donetyre;
			}
		}
		gStringTable[ST_Tyres+gNumberOfTyres] = name;
		Tyre2TyreIdMap[gNumberOfTyres] = pEntrantData->pEntrants[i].tyre;
		gNumberOfTyres++;
donetyre:

Share this post


Link to post
Share on other sites
could i not do something like


void SetArrayMaps(const char* cName, int iNum, int *iSize, _StringID sID, int* iArray)
{
int i;
for(i = 0; i < iSize; i++)
{
if (cName == gStringTable[sID+i])
{
return;

}
}
gStringTable[sID+iSize] = cName;
iArray[iSize] = iNum;
iSize++;
}



but i get an error for

gStringTable[sID+iSize] = cName;

error = error C2107: illegal index, indirection not allowed

[Edited by - Prog101 on September 19, 2007 5:38:18 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Prog101
I am using C and windows, i have the following code , this is just a snipit there is loads more all in the same format, can i make a function to handle all this

*** Source Snippet Removed ***


Uh... what the hell are you doing?

Why would you build a "string table" using strings that are already stored within the objects? (Keeping in mind that your table doesn't really store the strings, but simply copies the pointers?)

Why would you merge all the names into one "string table" - using some magic offsets - instead of separate ones?

As for your attempt - why would you pass 'iSize' by pointer?

Share this post


Link to post
Share on other sites

This topic is 3739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this