Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/12/2010, 14:13
luface2000
 
Fecha de Ingreso: octubre-2006
Mensajes: 169
Antigüedad: 18 años, 1 mes
Puntos: 2
No encuentro la solución a los errores

Hola,

llevo un montón de horas intentando solucionar los errores de este código y no lo con
consigo.
¿Me podéis ayudar?

Saludos.



Código:
#include <stdio.h>
#include <stdlib.h>

/*Declaració de constants*/
#define MAX_DRIVERS 50
#define MAX_RACES 50

/*Declaració de tipus*/
typedef enum {FALSE, TRUE} bool;

typedef struct{
	int idRace;
	float timeRace;
	float kmRace;
} tRaceInfo;

typedef struct{
	int idDriver;
	tRaceInfo dataDriver[MAX_RACES];
	int numRaces;
} tDriver;

typedef struct{
	tDriver drivers[MAX_DRIVERS];
	int numDrivers;
} tChampionship;

/* Predeclaració de funcions*/
void obtainReadingSequence(tRaceInfo *reading, bool *endSeq, int *idDriver);
void processReadingSequence(tChampionship *championship, int idDriver, tRaceInfo reading);
void findDriver(int idDrive, tChampionship *championship, int *index);
void findRace(tRaceInfo reading, tDriver *driver, int *pos);
void insertDriver(int idDriver, int index, tChampionship *championship);
void insertRace(tRaceInfo reading, int position, tDriver *driver);
void writeResult(tChampionship championship);

int main()
{
	tChampionship championship;
	bool endSeq;
	tRaceInfo reading;
	int idDriver;

	championship.numDrivers=0;
	endSeq = FALSE;
	obtainReadingSequence(&reading, &endSeq, &idDriver);
	while(!endSeq)
	{
		processReadingSequence(&championship, idDriver, reading);
		obtainReadingSequence(&reading, &endSeq, &idDriver);
	}
	writeResult(championship);
	//system("PAUSE");  //pause en Windows
	getchar();			//pause en Linux
	return 0;
}
/*accio obtainReadingSequence (sor reading: tRaceInfo,
							   sor endSeq: boolea,
							   sor idDriver: enter)*/
void obtainReadingSequence(tRaceInfo *reading, bool *endSeq, int *idDriver)
{
	int aux;
	scanf("%d", &aux);
	*endSeq = (aux == 0);
	if(!endSeq)
	{
		idDriver=aux;
		scanf("%d",&reading->idRace);
		scanf("%f",&reading->timeRace);
		scanf("%f",&reading->kmRace);
	}
}
/*accio processReadingSequence (entsor championship : tChampionship,
								ent idDriver: enter,
								ent reading: tRaceInfo )*/
void processReadingSequence( tChampionship *championship, int idDriver, tRaceInfo reading)
{
		int index;
		int position;

		findDriver(&championship, &idDriver, &index);
		findRace(&championship.drivers[index], &reading, &position);
}
//accio findDriver( ent idDriver: enter, entsor championship: tChampionship, sor index: enter )
void findDriver(int idDrive, tChampionship *championship, int *index)
{
	index=1;
	bool found = FALSE;
	while((!found) && (index<=(championship->numDrivers)))
	{
		found=(championship->drivers[index]).idDriver>=idDriver;
		if (!found)
		{
			index=index+1;
		}
	}
	if((!found)||(championship.drivers[index].idDriver<>idDriver))
	{
		insertDriver(&championship, index, idDriver)
	}
}
//accio findRace (ent reading: tRaceInfo, entsor driver: tDriver, sor pos: enter )
void findRace(tRaceInfo reading, tDriver *driver, int *pos)
{
	pos=1;
	bool found = FALSE;
	while((!found) && (pos<=driver->numRaces))
	{
		found=(driver->dataDriver[pos]).idRace>=reading.idRace;
		if(!found)
		{
			pos=pos+1;
		}
	}
	if((!found) || ((driver->dataDriver[pos]).idRace<>reading.idRace)
	{
		insertRace(&driver, pos, reading);
	}
}
//accio insertDriver(ent idDriver: enter ent index: enter,entsor championship: tChampionship, )
void insertDriver(int idDriver, int index, tChampionship *championship)
{
	int j;
	for (j=championship->numDrivers; j=index;j--)
	{
		championship->drivers[j+1]=championship->drivers[j];
	}
	(championship->drivers[index]).idDriver=idDriver;
	(championship->drivers[index]).numRaces=0;
	championship->numDrivers=championship->numDrivers+1;
}
//accio insertRace(ent reading : tRaceInfo , ent position : enter,entsor driver : tDriver)
void insertRace(tRaceInfo reading, int position, tDriver *driver)
{
	int j;
	for(j=(driver->numRaces);j=position;j--)
	{
		driver->dataDriver[j+1]=driver->dataDriver[j];
	}
	(driver->dataDriver[position]).idRace=reading.idRace;
	(driver->dataDriver[position]).timeRace=reading.timeRace;
	(driver->dataDriver[position]).kmRace=reading.kmRace;
	driver->numRaces=driver->numRaces + 1;
{
//accio writeResult (ent championship: tChampionship)
void writeResult(tChampionship championship)
{
	int j, k;
	float average;
	for(k=1;k=championship.numDrivers;k++)
	{
		writeInteger(championship.drivers[k].idDriver);
		printf(" ");
		for(j=1;j=(championship.drivers[k].numRaces);j++)
		{
			writeInteger(championship.drivers[k].dataDriver[j].idRace);
			printf(" ");
			average=(championship.drivers[k].dataDriver[j].kmRace*60)/(championship.drivers[k].dataDriver[j].timeRace);
			printf("%f",average);
			printf(" ");
		}
	}
}