no save
Assistance
Achat
News

Forum | programmation
[C] erreur de segmentation
tophe03, le mer. 22 nov. 2006 à 20:47:51
Bonjour

Je vois pas trop où j'aurais pu faire une erreur.
Voici une partie du code:

double *saisie_pol(HINSTANCE hinst, HWND hEdit, double *coefs, int deg)
{

for(q=deg;q>=0;q--)
{

DialogBoxParam(hinst, "DIALOG4", hEdit, (DLGPROC)Dialog4Proc, (LPARAM)hEdit);

coefs[q] = *cfs;
free(cfs);

}

return coefs;
}

char *saisie_degre(HINSTANCE hinst, HWND hEdit, polynome *p, double *coefs, int deg, int nb_poly, char *szBuffer1)
{
int m = 0;
char *szBuffer;
szBuffer = (char*)malloc(256*sizeof(char));

if (nb_poly == 0)
deg = (int)DialogBoxParam(hinst, "DIALOG2", hEdit, (DLGPROC)Dialog2Proc, (LPARAM)hEdit);
else if (nb_poly == 1)
deg = (int)DialogBoxParam(hinst, "DIALOG3", hEdit, (DLGPROC)Dialog3Proc, (LPARAM)hEdit);
new_pol(&p[nb_poly],deg);
saisie_pol(hinst, hEdit, coefs, deg);
init_pol(&p[nb_poly],coefs);
m += sprintf(szBuffer, "p%d(x) = %s", nb_poly + 1, afficher(&p[nb_poly], szBuffer1));
free(szBuffer1);

return szBuffer;
}

void MainWnd_Command(HINSTANCE hinst, HWND hEdit, WPARAM wParam)
{
char *buf, *temp;
int m, deg, nb_poly;
double *coefs, eval, x;
polynome *tampon, *p;

buf = (char*)malloc(256*sizeof(char));
temp = (char*)malloc(256*sizeof(char));
coefs = (double*)malloc((deg+1)*sizeof(double));
tampon = (polynome*)malloc(2*sizeof(polynome));
p = (polynome*)malloc(2*sizeof(polynome));

m = 0;

if (LOWORD(wParam) == IDM_DERIV)
{

m = sprintf(buf, "Polynôme à dériver:\r\n %s", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0, temp));
free(temp);
tampon[0] = derive(p[0]);
m += sprintf(buf + m, "\r\n\r\n p1'(x) = %s", afficher(&tampon[0], temp));
free(temp);
}

else if (LOWORD(wParam) == IDM_SOMME)
{

m = sprintf(buf + m, "Polynômes à ajouter:\r\n %s\r\n ", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0, temp));
free(temp);
m += sprintf(buf + m, "%s", saisie_degre(hinst, hEdit, &p[1], coefs, deg, 1, temp));
free(temp);
tampon[0] = add(p[0],p[1]);
m += sprintf(buf + m, "\r\n\r\n p1(x) + p2(x) = %s", afficher(&tampon[0], temp));
free(temp);
}
SetWindowText(hEdit, buf);
free(tampon);
free(p);
free(buf);
}


Pour ce qui est de la dérivation (IDM_DERIV), ça marche.
Pour la somme (IDM_SOMME), c'est là que j'ai l'erreur.
Si j'intercale des "SetWindowText(hEdit, buf);" dans IDM_SOMME, les polynomes p[0] et p[1] s'affichent correctement. C'est après que ça se gâte, au niveau de tampon[0]=add(p[0],p[1]).

Si tu vois qcc de louche...
Merci
Précédentmamiemando
nov. 06
mamiemando
nov. 06
Suivant
REPONSES
mamiemando
nov. 06
tophe03
nov. 06
mamiemando
nov. 06
Char Snipeur
nov. 06
tophe03
nov. 06
mamiemando
nov. 06
Char Snipeur
nov. 06
tophe03
nov. 06
Version Web
Réalisé par RedShift
no save