Erreur de segmentation

Fermé
DAD - 2 avril 2008 à 17:59
mype Messages postés 2435 Date d'inscription jeudi 1 novembre 2007 Statut Membre Dernière intervention 16 août 2010 - 2 avril 2008 à 19:18
Bonjour,on a un prb ds un algorithme le prb c'est une erreur de segmentation
# include<stdio.h>
struct releve
{
float tempmin;
float tempmax;
float hygrometrie;
float pluie;
};
void saisie(int taille,struct releve t[])
{
for(int i=0; i<taille; i++)
scanf("%f%f%f%f\n",&t[i].tempmin,&t[i].tempmax,&t[i].hygrometrie,&t[i].pluie);
}
void affiche(int taille,struct releve t[])
{
for(int i=0; i<taille; i++)
printf("tempmin=%f,tempmax=%f,hygrometrie=%f,pluie=%f\n",t[i].tempmin,t[i].tempmax,t[i].hygrometrie,t[i].pluie);
}
void calcul(struct releve t[], int taille)
{
int s[taille];
int indicemin=0;
int indicemax=0;
int tempmin;
s[0]=-1;

for(int i=1; i<taille; i++)

if (t[i].tempmin>t[indicemax].tempmin)
{
s[i]=-1;
s[indicemax]=i;
indicemax=i;
}
else if (t[i].tempmin<t[indicemin].tempmin)
{
s[i]=indicemin;
indicemin=i;
}
else if ((t[i].tempmin<t[indicemax].tempmin)&&(t[i].tempmin>t[indicemin].tempmin))
{int tmp=s[indicemin];
while (!(t[tmp].tempmin<t[i].tempmin,tempmin<t[s[tmp]].tempmin))
{
tmp=s[tmp];
}
s[i]=s[tmp];
s[tmp]=i;
}
}
void afficheTab(struct releve t[], int s[], int indicemin, int taille)
{
for (int i=0; i<taille; i++)
{
printf("%f\n", t[indicemin].tempmin);
indicemin=s[indicemin];
};
}
int main()
{
int taille;

int indicemin;
printf("entrer la taille du tableau\n");
scanf("%d",&taille);
struct releve t[taille];
int s[taille];
saisie(taille,t);
affiche(taille,t);
calcul(t,taille);
afficheTab(t,s,indicemin,taille);
}

2 réponses

mype Messages postés 2435 Date d'inscription jeudi 1 novembre 2007 Statut Membre Dernière intervention 16 août 2010 436
2 avril 2008 à 18:16
tu n'alloues pas de memoire ni a t ni a s
il faut que tu utilises des malloc...
0
re,
Est ce que vous pourriez me le corriger SVP car g aucune idée pr l'utilisation du malloc.
0
mype Messages postés 2435 Date d'inscription jeudi 1 novembre 2007 Statut Membre Dernière intervention 16 août 2010 436 > DAD
2 avril 2008 à 19:18
ah ben oui finalement peut etre meme pas besoin de malloc...
essaye la technique de lami20j en initialisant indicemin dans le main
0
lami20j Messages postés 21331 Date d'inscription jeudi 4 novembre 2004 Statut Modérateur, Contributeur sécurité Dernière intervention 30 octobre 2019 3 567
2 avril 2008 à 18:31
Salut,

ta variable indicemin dans main n'est pas initialisé
donc tu passes quelle valeur à la fonction
afficheTab(t,s,indicemin,taille); 
??

0