|
|
|
|
Bonjour,
j'ai un programme en C qui utilise une fonction nextHoraire avec un pointeur en perametre:
#define NBHORAIRES 10
const horaire Horaires[nbHoraires]={
{6,0} ,{6,30} ,{7,0} ,{7,30} ,{8,10},
{8,45},{10,15},{12,10},{14,25},{14,45}
};
horaire nextHoraire(horaire hr, horaire *h , int nbHoraires )
{
//horaire h_aux={h.heures,h.minutes};
int i=0;
while ((hr.heures > h[i]->heures) && (i< nbHoraires) )
i++;
if(i== nbHoraires )
return *h[0];
while(( hr.minutes > h[i]->minutes) && i< nbHoraires )
if (h[i]->heures > hr.heures)
return *h[i];
else
i++;
if( (i== nbHoraires) || ( (hr.heures >= h[nbHoraires-1]->heures) && ( hr.minutes >= h [nbHoraires-1]->minutes) ) )
return *h[0];
else
return *h[i];
}
que j'utilise dans un main de la façon suivante:
horaire heure_reelle={4,50};
prochainHoraire=nextHoraire(heure_reelle,&Horaire,NBHORAIRES);
A la compilation j'ai une erreur qui me renvoie à la ligne de déclaration de nextHoraire:
horaire nextHoraire(horaire hr, horaire *h , int nbHoraires )
et qui me dit:
Error 28 "ex_rfid_projet.c" Line 142(68,69): Expecting an identifier.
Quelqu'un pourrait-il maider ou m'expliquer ce que peut signifier cette erreur?
je vous remercie d'avance
Configuration: Windows XP Internet Explorer 7.0
Après avoir déclaré:
|
Merci, j'avais déjà essayé en ecrivant ma foonction de la maniere suivante:
|
Ok, j'ai remis la taille du tableau en parametre.
|
Bon, on va pas tourner autour du pot pendant 8 jours; voici un code qui se compile bien: #include<stdio.h>
#define NBHORAIRES 10
typedef struct
{
int heures;
int minutes;
} horaire;
const horaire Horaires[NBHORAIRES] =
{
{6, 0},{ 6,30},{ 7, 0},{ 7,30},{ 8,10},
{8,45},{10,15},{12,10},{14,25},{14,45}
};
horaire nextHoraire (horaire hr, const horaire h[], int nbHor)
{
int i = 0;
while ((hr.heures > h[i].heures) && (i<nbHor))
i++;
if (i == nbHor)
return h[0];
while ((hr.minutes > h[i].minutes) && (i< nbHor))
if (h[i].heures > hr.heures)
return h[i];
else
i++;
if ( (i != nbHor) && ((hr.heures < h[nbHor-1].heures) || (hr.minutes < h[nbHor-1].minutes)) )
return h[i];
return h[0];
}
int main()
{
horaire heure_reelle = {18,44};
horaire prochainHoraire = nextHoraire (heure_reelle, Horaires, NBHORAIRES);
printf ("Prochain horaire: %d h %d mn\n", prochainHoraire.heures, prochainHoraire.minutes);
return (0);
}Bonne continuation. |