[DEV C++] pb pour utiliser le debugueur

tophe03 Messages postés 327 Date d'inscription   Statut Membre Dernière intervention   -  
tophe03 Messages postés 327 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

J'ai écrit un prog en C sur Dev C++. A la compilation, aucune erreur n'est trouvée. Mais lorsque je lance le fichier exe, ça bugue. J'essaie de lancer le debugueur, mais rien ne se passe. J'ai pourtant coché "Yes" dans "Projet>Options du projet>Compilateur>Editeur de liens>Générer des informations de débogage" et j'ai entré dans "Projet>Options du projet>Paramètres>Compilateur" -g3 -gstabs .

Je suis novice dans l'utilisation d'un débugueur et je l'utilise peut-être mal donc si qqn pouvait m'aider...

Merci
A voir également:

15 réponses

Utilisateur anonyme
 
slt
pourrait tu preciser quandtu dit que ca bugge ?
0
tophe03 Messages postés 327 Date d'inscription   Statut Membre Dernière intervention   5
 
salut

lorsque je lance l'exe, la fenêtre windows s'ouvre sans problème (j'ai écrit le prog avec l'API windows), et lorsque je choisis un sous-menu, ça part bien mais ensuite une fenêtre apparaît avec "polynomes.exe a rencontré un problème et doit fermer. Nous vous prions de nous excuser pour le désagrément encouru..." en me demandant si je veux envoyer le rapport d'erreur.

j'espère que ça aidera...
0
tophe03 Messages postés 327 Date d'inscription   Statut Membre Dernière intervention   5
 
salut

lorsque je lance l'exe, la fenêtre windows s'ouvre sans problème (j'ai écrit le prog avec l'API windows), et lorsque je choisis un sous-menu, ça part bien mais ensuite une fenêtre apparaît avec "polynomes.exe a rencontré un problème et doit fermer. Nous vous prions de nous excuser pour le désagrément encouru..." en me demandant si je veux envoyer le rapport d'erreur.

j'espère que ça aidera...
0
liehuos001 > tophe03 Messages postés 327 Date d'inscription   Statut Membre Dernière intervention  
 
je croi qu il ya un defaut dans le dev-c++ car je recoi la meme message de bugue c'est pour ca que ce programme est gratuit
0
Utilisateur anonyme
 
oui devc++ est gratuit mais je ne pense pas qui soit aussi inperformant sinon nouson l'utiliserait pas en cours... ast tu la derniere version de dev c++ ?
sinon essaye c++ builder
0
tophe03 Messages postés 327 Date d'inscription   Statut Membre Dernière intervention   5
 
salut

J'ai la version 4.9.9.2 de Dev C++. Je sais pas si c'est le dernière version.
0
Char Snipeur Messages postés 9813 Date d'inscription   Statut Contributeur Dernière intervention   1 299
 
Salut.
Je pense qu'il y a quelques bug dans DEv Cpp, mais ils ne sont pas très génant, et c'est un programme de très bonne qualité.
Je résume ton prb: tu as cocher "gérer des informations de debugage" dans DevCpp, tu as recompiler, et lorsque tu clic sur debug il ne se passe rien ?
essai sans -g3 -gstab, normalement, il n'y en a pas besoin.
Pour vérifier que le problème viens bien de DevCpp, tu va dans une console, et tu tape :
"gdb {nom du programme}"
ensuite, une foi dans le debugueur, tu tape "run"
0
mamiemando Messages postés 33778 Date d'inscription   Statut Modérateur Dernière intervention   7 884
 
Pour moi il faut juste compiler avec l'option -g et lancer gdb :
gcc -W -Wall -g plop.c -o plop.exe
gdb plop.exe

Supposons que plop.exe prenne les paramètre arg1 arg2, dans gdb :
r arg1 arg2
bt

(bt affiche la pile d'éxecution à l'endroit ou le programme plante, en particulier tu sais exactement dans quelle fonction ça a planté)

Bonne chance
0
tophe03 Messages postés 327 Date d'inscription   Statut Membre Dernière intervention   5
 
salut

ça commence à devenir compliqué pour moi, je débute. j'aurais besoin de qqs explications.
quand tu dis "lancer gdb", c'est lancer le gdb.exe qui se trouve dans Dev-Cpp>bin? Si c'est le cas, que faut-il faire exactement?

merci pour ton aide
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Char Snipeur Messages postés 9813 Date d'inscription   Statut Contributeur Dernière intervention   1 299
 
Je ne comprend pas ce que tu ne comprend pas. Il suffit de lancer gdb depuis une console avec comme argument le nom de ton prog (comme je te l'ai dit)
Il y a quelque chose que je ne comprend pas. Quand tu dit que tu as fait un programme avec l'API win, c'est un programme qui fait des fenetre windows? Si c'est le cas, on est pas obliger de faire du C++ pour ça ?
sinon, as tu mis des points d'arret ou effectué du pas à pas dans DevCpp avant de lancer le debugueur?
0
mamiemando Messages postés 33778 Date d'inscription   Statut Modérateur Dernière intervention   7 884
 
Je pense que tu peux lancer gdb.exe à partir d'une commande msdos (démarrer exécuter cmd). Mais il y a peut être directement ce qu'il faut dans devcpp.

Bonne chance
0
tophe03 Messages postés 327 Date d'inscription   Statut Membre Dernière intervention   5
 
bonjour

je suis allé dans la console. j'ai tapé "gdb nomprogramme". j'ai eu ensuite l'invite (gdb). j'ai tapé "b nomprogramme.c:138." la ligne "breakpoint 1 at 0x40194c: file nomprogramme.c, line 138" est apparue. puis à l'invite (gdb) j'ai tapé "r". la ligne "Starting program: nomprogramme.exe" est apparue. ensuite il ne se passe rien, je n'ai plus d'invite. c'est la meme chose lorsque je mets un point d'arrêt avec "b nomfonction". que faire dans ce cas?
0
mamiemando Messages postés 33778 Date d'inscription   Statut Modérateur Dernière intervention   7 884
 
Tu dois avoir une boucle infinie avant ton breakpoint. Mais un break point au début du main et avance pas à pas (s ou n). Je te conseille de rajouter des prtinf dans ton programme pour localiser plus rapidement le problème :
int main(){
  //...
  printf("debug 1\n");
  //...
  printf("debug 2\n");
  //...
  printf("debug 3\n");
  //...
  printf("debug 4\n");
  //...
  return 0;
}


Si ton programme ne boucle pas mais plante, pas besoin de breakpoint. Tu le lances (r) et tu affiches la pile (bt).

Bonne chance
0
tophe03 Messages postés 327 Date d'inscription   Statut Membre Dernière intervention   5
 
re

Même sans mettre de breakpoint, lorsque je lance, il bloque après avoir mis "starting program...".
0
[Guillaume] Messages postés 41 Date d'inscription   Statut Membre Dernière intervention   10
 
Salut à vous...

Moi aussi j'ai un pb avec Dev C++ donc si vous pourriez m'aider au passage ca serait sympas...

Je m'explique je fais un programme, il n'y a aucunes erreurs et lorsque je clique sur "Executer" la fenêtre du programme apparait seulement durant 1/2 secondes elle ne s'affiche pas constamment bref c'est chiant car on peut pas voir ni utiliser son propre programme (même lorsque je fais Ctrl+F10 la fenêtre fais de même)...

Savez-vous d'où cela pourrait venir et comment corriger ce facheux pb car là ça me saoule...
Merci à ceux qui pourront m'aider :(
0
Char Snipeur Messages postés 9813 Date d'inscription   Statut Contributeur Dernière intervention   1 299
 
salut.
Tu aurai du creer un nouveau message pour ton problème, il n'a rien a voir avec celui qui est en cour.
pour te répondre. Si ta fenetre clignote comme je le comprend, c'est en effet très etrange.
Si elle se ferme et que le programme se termine, c'est peut être normal.
Si tu n'a aucune demande utilisateur de la par de ton programme, c'est normal. Sinon, il doit y avoir une erreur quelque par qui même à un abort ou exit.
0
mamiemando Messages postés 33778 Date d'inscription   Statut Modérateur Dernière intervention   7 884
 
Guillaume : ouvre un nouveau post et on te répondra
Tophe 03 : c'est normal il faut mettre un breakpoint au début du main car visiblement tu as une boucle infinie. Il faut avancer pas à pas dans le programme pour voir où elle survient.

Méthode 1 : avec des printf
#include <stdio.h>

int main(){
  int i=0,j;
  printf("debug 1\n"); <-- le programme affiche debug1
  for(j=5;j==i;++j){ // <-- boucle infinie
    //...
  }
  printf("debug 2\n");<-- le programme n'affiche pas debug2
  return 0;
}
Ainsi on sait que la boucle infinie survient entre printf("debug 1\n"); et printf("debug 2\n");

Méthode 2 : avec gdb
int main(){
  int i=0,j; // placer le breakpoint ici et avancer pas à pas (n ou s)
  for(j=5;j==i;++j){ // <-- boucle infinie
    //...
  }
  return 0;
}

En avançant pas à pas tu verras que tu n'arrives jamais à sortir de la boucle.

Bonne chance
0
tophe03 Messages postés 327 Date d'inscription   Statut Membre Dernière intervention   5
 
salut

J'ai encore essayé avec gdb comme tu m'as dit mais toujours pareil. Avec la 1ère méthode, je vois à quel endroit il plante mais je ne voit pas qu'est ce qui peut le faire planté.
0
mamiemando Messages postés 33778 Date d'inscription   Statut Modérateur Dernière intervention   7 884
 
Copie colle le code en question car là je ne peux pas t'aider plus.
0
tophe03 Messages postés 327 Date d'inscription   Statut Membre Dernière intervention   5
 
Voici une partie du code

case WM_COMMAND:
if (LOWORD(wParam) == IDM_EVAL || LOWORD(wParam) == IDM_DERIV || LOWORD(wParam) == IDM_INTEGR || LOWORD(wParam) == IDM_SOMME || LOWORD(wParam) == IDM_DIFF || LOWORD(wParam) == IDM_PROD || LOWORD(wParam) == IDM_DIV)
{

MainWnd_Titre(hwnd, wParam);
MainWnd_Command(hinst, hEdit, wParam);

}

c'est ici que ça plante alors que les autres commandes fonctionnent sans problème
.../...


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

double *coefs;
coefs = (double*)malloc((deg+1)*sizeof(double));

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

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

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

}

return coefs;
}

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

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);
coefs = saisie_pol(hinst, hEdit, 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, 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_EVAL)
{

m = sprintf(buf, "Polynôme à évaluer:\r\n %s", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0));
DialogBoxParam(hinst, "DIALOG5", hEdit,(DLGPROC)Dialog5Proc, (LPARAM)hEdit);
x = *xe;
eval = eval_x(p[0],x);
m += sprintf(buf + m, "\r\n\r\n p1(%f) = %f", x, eval);
free(xe);
}

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

m = sprintf(buf, "Polynôme à dériver:\r\n %s", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0));
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_INTEGR)
{

m += sprintf(buf + m, "Polynôme à intégrer:\r\n %s", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0));
tampon[0] = integre(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));
m += sprintf(buf + m, "%s", saisie_degre(hinst, hEdit, &p[1], coefs, deg, 1));
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);
}

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

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

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

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

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

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

free(tampon);
free(p);
SetWindowText(hEdit, buf);
free(buf);
}
0
mamiemando Messages postés 33778 Date d'inscription   Statut Modérateur Dernière intervention   7 884
 
Euh tu peux m'isoler la section que tu as isolé comme étant bloquante, parce que là vu que j'ai pas tout le code je peux pas tester chez moi ? Et peux tu encadrer ton code avec les balises code (au dessus de la boîte dans laquelle tu tapes ton texte)
0
tophe03 Messages postés 327 Date d'inscription   Statut Membre Dernière intervention   5
 
BOOL APIENTRY Dialog2Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    switch (uMsg)
    {
      case WM_INITDIALOG:
      {
           SetFocus(GetDlgItem(hDlg, IDE_EDIT1));
           return FALSE;
      }
      break;

      case WM_COMMAND:
      {
           if (LOWORD(wParam) == IDOK)
           {
                deg = GetDlgItemInt(hDlg,IDE_EDIT1,NULL,TRUE);
                if (deg > 0)
                   EndDialog(hDlg, deg);
                else MessageBox(hDlg, "Valeur incorrecte", "Attention!", MB_OK | MB_ICONWARNING);
                   return TRUE;
           }
      }
      break;

      default:
         return FALSE;
    }
}
/******************************************************************************/
BOOL APIENTRY Dialog3Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    
    switch (uMsg)
    {
      case WM_INITDIALOG:
      {
           SetFocus(GetDlgItem(hDlg, IDE_EDIT2));
           return FALSE;
      }
      break;

      case WM_COMMAND:
      {
           if (LOWORD(wParam) == IDOK )
           {
                deg = GetDlgItemInt(hDlg,IDE_EDIT2,NULL,TRUE);
                if (deg > 0)
                   EndDialog(hDlg, deg);
                else MessageBox(hDlg, "Valeur incorrecte", "Attention!", MB_OK | MB_ICONWARNING);
                return TRUE;
           }
      }
      break;
         
      default:
         return FALSE;
    }
}

/******************************************************************************/
BOOL APIENTRY Dialog4Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    LOGFONT lf3;
    HFONT NewFont3, OldFont3;
    
    switch (uMsg)
    {
      case WM_INITDIALOG:
      {
           SetFocus(GetDlgItem(hDlg,IDE_EDIT3));
           return FALSE;
      }
      break;

      case WM_PAINT:
      {

           char st3[56];
           sprintf(st3, "Entrez le coefficient du terme de degré %d :", q);
           PAINTSTRUCT ps3;
           HDC hdc3 = BeginPaint(hDlg, &ps3);
           SetBkMode(hdc3, TRANSPARENT);
           
           ZeroMemory(&lf3, sizeof(LOGFONT));
           lstrcpy(lf3.lfFaceName,"MS Sans Serif");
           lf3.lfHeight = 8;
           lf3.lfItalic = FALSE;
           lf3.lfWeight = FW_NORMAL;

           NewFont3 = CreateFontIndirect(&lf3);
           OldFont3 = SelectObject(hdc3,NewFont3);
           TextOut(hdc3, 24, 18, st3 , lstrlen(st3));
           SelectObject(hdc3, OldFont3);
           DeleteObject(NewFont3);
           
           EndPaint(hDlg, &ps3);
           return FALSE;
      }
      break;
      
      case WM_COMMAND:
      {
           if (LOWORD(wParam) == IDOK )
           {
               
               char *string3;
               string3 = (char*)malloc(256*sizeof(char));
               cf = (double*)malloc(sizeof(double));

               GetDlgItemText(hDlg, IDE_EDIT3, string3, 256);
               *cf = atof(string3);
               EndDialog(hDlg, 0);
           }
           return TRUE;
      }
      break;
         
      default:
         return FALSE;
    }
}
/******************************************************************************/
BOOL APIENTRY Dialog5Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    switch (uMsg)
    {
      case WM_INITDIALOG:
      {
           SetFocus(GetDlgItem(hDlg,IDE_EDIT4));
           return FALSE;
      }
      break;

      case WM_COMMAND:
      {
           if (LOWORD(wParam) == IDOK )
           {
               
               char *string4;               
               string4 = (char*)malloc(256*sizeof(char));
               xe = (double*)malloc(sizeof(double));
               
               GetDlgItemText(hDlg, IDE_EDIT4, string4, 256);
               *xe = atof(string4);
               EndDialog(hDlg, 0);
           }
           return TRUE;
      }
      break;
         
      default:
         return FALSE;
    }
}

/******************************************************************************/

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

    double *coefs;
    coefs = (double*)malloc((deg+1)*sizeof(double));
    
	for(q=deg;q>=0;q--)
	{
         
      DialogBoxParam(hinst, "DIALOG4", hEdit, (DLGPROC)Dialog4Proc, (LPARAM)hEdit);
      
      coefs[q] = *cf;
      free(cf);

	}
	
	return coefs;
}

char *saisie_degre(HINSTANCE hinst, HWND hEdit, polynome *p, double *coefs, int deg, int nb_poly)
{
     int m = 0;
     char *szBuffer, *szBuffer1;
     szBuffer = (char*)malloc(256*sizeof(char));
     szBuffer1 = (char*)malloc(256*sizeof(char));
     p = (polynome*)malloc(2*sizeof(polynome));
     
     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);
     coefs = saisie_pol(hinst, hEdit, 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, 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_EVAL)
     {
           
           m = sprintf(buf, "Polynôme à évaluer:\r\n    %s", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0));
           DialogBoxParam(hinst, "DIALOG5", hEdit,(DLGPROC)Dialog5Proc, (LPARAM)hEdit);
           x = *xe;
           eval = eval_x(p[0],x);
           m += sprintf(buf + m, "\r\n\r\n    p1(%f) = %f", x, eval);
           free(xe);
     }
         
     else if (LOWORD(wParam) == IDM_DERIV)
     {

           m = sprintf(buf, "Polynôme à dériver:\r\n    %s", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0));
           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_INTEGR)
     {

           m += sprintf(buf + m, "Polynôme à intégrer:\r\n    %s", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0));
           tampon[0] = integre(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));
           m += sprintf(buf + m, "%s", saisie_degre(hinst, hEdit, &p[1], coefs, deg, 1));
           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);
     }
              
     else if (LOWORD(wParam) == IDM_DIFF)
     {
           
           m += sprintf(buf + m, "Polynômes à soustraire:\r\n    %s\r\n    ", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0));
           m += sprintf(buf + m, "%s", saisie_degre(hinst, hEdit, &p[1], coefs, deg, 1));
           tampon[0] = diff(p[0],p[1]);
           m += sprintf(buf + m, "\r\n\r\n    p1(x) - p2(x) = %s", afficher(&tampon[0], temp));
           free(temp);
     }
	          
     else if (LOWORD(wParam) == IDM_PROD)
     {

           m += sprintf(buf + m, "Polynômes à multiplier:\r\n    %s\r\n    ", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0));
           m += sprintf(buf + m, "%s", saisie_degre(hinst, hEdit, &p[1], coefs, deg, 1));
           tampon[0] = mult(p[0],p[1]);
           m += sprintf(buf + m, "\r\n\r\n    p1(x) * p2(x) = %s", afficher(&tampon[0], temp));
           free(temp);
     }
	          
     else if (LOWORD(wParam) == IDM_DIV)
     {

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

Je pense que le problème survient au moment d'afficher le résultat.
0
mamiemando Messages postés 33778 Date d'inscription   Statut Modérateur Dernière intervention   7 884
 
Ben ouais mais là il n'y a pas de main dans ton code donc comment je compile ?
Tu ne m'a toujours pas indiqué ou tu avais localisé que ça bloquait avait les printf...
0
tophe03 Messages postés 327 Date d'inscription   Statut Membre Dernière intervention   5
 
Voici tout le code, il y a 4 fichiers:

->resource.h:

#define IDM_OPEN 1
#define IDM_SAVE 2
#define IDM_QUIT 3
#define IDM_FONT 4
#define IDM_TEXTCOLOR 5
#define IDM_EVAL 6
#define IDM_DERIV 7
#define IDM_INTEGR 8
#define IDM_SOMME 9
#define IDM_DIFF 10
#define IDM_PROD 11
#define IDM_DIV 12
#define IDM_ABOUT 13

#define IDE_EDIT1 101
#define IDE_EDIT2 102
#define IDE_EDIT3 103
#define IDE_EDIT4 104

UINT style;

HINSTANCE hinst;

LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT APIENTRY EditProc(HWND, UINT, WPARAM, LPARAM);
BOOL APIENTRY Dialog1Proc(HWND, UINT, WPARAM, LPARAM);
BOOL APIENTRY Dialog2Proc(HWND, UINT, WPARAM, LPARAM);
BOOL APIENTRY Dialog3Proc(HWND, UINT, WPARAM, LPARAM);
BOOL APIENTRY Dialog4Proc(HWND, UINT, WPARAM, LPARAM);
BOOL APIENTRY Dialog5Proc(HWND, UINT, WPARAM, LPARAM);

#ifdef STRICT
  WNDPROC wpOrigEditProc ;
#else
  FARPROC wpOrigEditProc ;
#endif

#ifndef POLY_H
#define POLY_H

typedef struct
{
int degre;
double *coef;
}
polynome;

extern double puis_n(double, int);
extern int maxint(int, int);
extern double vabs(double);
extern void oppose(double*, int);
extern void new_pol(polynome*, int);
extern void init_pol(polynome* ,double*);
extern void copy(polynome, polynome*);
extern void free_pol(polynome*);
extern int est_nul(polynome);
extern char *afficher(polynome*, char*);
extern double eval_x(polynome, double);
extern polynome derive(polynome);
extern polynome integre(polynome);
extern polynome add(polynome,polynome);
extern polynome diff(polynome,polynome);
extern polynome mult(polynome,polynome);
extern void division_euc(polynome,polynome,polynome*,polynome*);

double *saisie_pol(HINSTANCE, HWND, int);
char *saisie_degre(HINSTANCE, HWND, polynome*, double*, int, int);
void MainWnd_Command(HINSTANCE, HWND, WPARAM);
void MainWnd_Titre(HWND, WPARAM);

#endif


->resource.c:

#include <windows.h>

#include "resource.h"


LEMENU MENU
BEGIN
  POPUP "Fichier"
    BEGIN
       MENUITEM "Ouvrir\tCtrl+O", IDM_OPEN
       MENUITEM "Enregistrer sous\tCtrl+S", IDM_SAVE
       MENUITEM "Quitter\tAlt+F4", IDM_QUIT
    END
  
  POPUP "Format"
    BEGIN
       MENUITEM "Police", IDM_FONT
       MENUITEM "Couleur", IDM_TEXTCOLOR
    END
  
  POPUP "Opération"
    BEGIN
       MENUITEM "Evaluation\tCtrl+E", IDM_EVAL
       MENUITEM "Dérivation\tCtrl+F", IDM_DERIV
       MENUITEM "Intégration\tCtrl+I", IDM_INTEGR
       MENUITEM SEPARATOR
       MENUITEM "Somme\tCtrl+A", IDM_SOMME
       MENUITEM "Différence\tCtrl+D", IDM_DIFF
       MENUITEM "Produit\tCtrl+P", IDM_PROD
       MENUITEM "Division Euclidienne\tCtrl+Q", IDM_DIV
    END
  POPUP "Aide"
    BEGIN
       MENUITEM "A propos...", IDM_ABOUT
    END
END

LesAccel ACCELERATORS
BEGIN
    "O", IDM_OPEN, CONTROL, VIRTKEY
    "S", IDM_SAVE, CONTROL, VIRTKEY
    "E", IDM_EVAL, CONTROL, VIRTKEY
    "F", IDM_DERIV, CONTROL, VIRTKEY
    "I", IDM_INTEGR, CONTROL, VIRTKEY
    "A", IDM_SOMME, CONTROL, VIRTKEY
    "D", IDM_DIFF, CONTROL, VIRTKEY
    "P", IDM_PROD, CONTROL, VIRTKEY
    "Q", IDM_DIV, CONTROL, VIRTKEY
    VK_F1, IDM_ABOUT, VIRTKEY
END

DIALOG1 DIALOG 60, 60, 160, 80
          STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
          CAPTION "A propos"
          FONT 8, "MS Sans Serif"

BEGIN
    DEFPUSHBUTTON "Ok", IDOK, 56, 50, 42, 12
    ICON 2, -1, 20, 15, 32, 32
    LTEXT "Mon beau programme !", -1, 60, 18, 80, 10
END

DIALOG2 DIALOG 60, 60, 250, 70
          STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
          CAPTION "Saisie du degré d'un polynôme"
          FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON "OK", IDOK, 104, 42, 42, 12
    EDITTEXT IDE_EDIT1, 160, 15, 74, 12
    LTEXT "Entrez le degré du polynôme p1 :", -1, 24, 18, 120, 10
END

DIALOG3 DIALOG 60, 60, 250, 70
          STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
          CAPTION "Saisie du degré d'un polynôme"
          FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON "OK", IDOK, 104, 42, 42, 12
    EDITTEXT IDE_EDIT2, 160, 15, 74, 12
    LTEXT "Entrez le degré du polynôme p2 :", -1, 24, 18, 120, 10
END

DIALOG4 DIALOG 60, 60, 250, 70
          STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
          CAPTION "Saisie des coefficients du polynôme"
          FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON "OK", IDOK, 104, 42, 42, 12
    EDITTEXT IDE_EDIT3, 160, 15, 74, 12
END

DIALOG5 DIALOG 60, 60, 250, 70
          STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
          CAPTION "Evaluation d'un polynôme"
          FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON "OK", IDOK, 104, 42, 42, 12
    EDITTEXT IDE_EDIT4, 160, 15, 74, 12
    LTEXT "Entrez le point auquel vous souhaitez evaluer le polynôme : ", -1, 24, 18, 120, 10
END


->poly.c:

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

#include "resource.h"


/* Fonction d'allocation de memoire lors de la creation
On passe un pointeur vers un polynome de manière a pouvoir directement le
modifier, ainsi que son degre de manière a allouer directement de la place en
memoire */

/* Calcul de la n-ieme puissance d'un nombre flottant */
double puis_n(double f, int n)
{
	if(n<=0)	return(1.0);
	else
	{
	double ret=1;
		while(n>0)
		{
		ret *= f;
		n--;
		}
	return ret;
	}
}

/* Calcul du maximum de deux nombres entiers */
int maxint(int x, int y)
{
	if(x > y)	return x;
	else	return y;
}

/* Calcul de la valeur absolue d'un nombre flottant */
double vabs(double x)
{
	if(x <= 0.0)	return(-x);
	else		return x;
}

/* Fonction nécessaire a la soustraction (remplace chaque coefficient par son
opposé */
void oppose(double *coefs,int deg)
{
int i;
	for(i=0;i<=deg;i++)
	{
	coefs[i] = -coefs[i];
	}
}


void new_pol(polynome *p,int deg)
{
int i;
	if(deg>0)	
	{
	p->degre = deg;
	p->coef = (double*)calloc(deg+1,sizeof(double));
	}
	else
	{
	p->degre = 0;
	p->coef = (double*)calloc(1,sizeof(double));
	}
}

/* Initialisation des coefficients du pointeur vers un polynome passé en param
avec le tableau de flottant tab */
void init_pol(polynome *p,double *tab)
{
int i;
	for(i=0;i<=p->degre;i++)
	{
	p->coef[i] = tab[i];
	}
}

/* Libère la memoire allouée pour un polynome */
void free_pol(polynome *p)
{
	p->degre=0;
	free(p->coef);
}

/* Fonction permettant de copier un polynome dans un autre */
void copy(polynome source,polynome *dest)
{
free_pol(dest);
new_pol(dest,source.degre);
init_pol(dest,source.coef);
}

/* Pour afficher correctement un polynome ... */
char *afficher(polynome *p, char *szBuffer1)
{
int i, j = 0;
char si;
szBuffer1 = (char*)malloc(256*sizeof(char));

	for(i=p->degre; i>=0; i--)
	{
	    if(p->coef[i]<0.0)	si = '-';
	    else
        {
            if (i == p->degre) si = ' ';
            else si = '+';
        }
		
		if(i == 0)
             break;
		if(vabs(p->coef[i]) == 1.0)
		{
             if (i == 1)
                j += sprintf(szBuffer1 + j, " %c x",si);
             else
                j += sprintf(szBuffer1 + j, " %c x^%d",si,i);
        }
		else if(p->coef[i] != 0.0)
		{
		     if (i == 1)
		        j += sprintf(szBuffer1 + j, " %c %f x",si,vabs(p->coef[i]));
             else
                j += sprintf(szBuffer1 + j, " %c %f x^%d",si,vabs(p->coef[i]),i);
        }
		
	}
	if(p->coef[0] != 0)
        j += sprintf(szBuffer1 + j, " %c %f",si,vabs(p->coef[0]));
j += sprintf(szBuffer1 + j, "\r\n");
szBuffer1[j] = '\0';
return szBuffer1;
}

/* Evaluation d'un polynome en un x donné, ... pour l'instant rien de bien
compliqué */
double eval_x(polynome p,double x)
{
int i;
double ret = 0.0;
	for(i=0;i<=p.degre;i++)
	{
	ret +=  p.coef[i]*puis_n(x,i);
	}
return ret;
}

/* Teste si tous les coefficient d'un polynomes sont nuls */
int est_nul(polynome p)
{
int i,ret=1;
	for(i=0;i<=p.degre;i++)
	{
		if(p.coef[i] != 0)
		{
		ret = 0;
		break;
		}
	}
return ret;
}

/* Derivation de polynome */
polynome derive(polynome p)
{
polynome ret;
int i;

	if(p.degre == 0 || est_nul(p))
	{
	new_pol(&ret,0);
	}
	else
	{
	    new_pol(&ret,p.degre-1);
		for(i=0;i<=ret.degre;i++)
		{
		ret.coef[i] = ((double)(i+1))*p.coef[i+1];
		}
	}
return ret;
}

/* Integration de polynomes */
polynome integre(polynome p)
{
polynome ret;
int i;

	if(est_nul(p))
	{
	new_pol(&ret,0);
	ret.coef[0] = 1;
	}
	else if(p.degre == 0)
	{
	new_pol(&ret,1);
	ret.coef[1] = p.coef[0];
	}
	else
	{
	    new_pol(&ret,p.degre+1);
	    ret.coef[0] = 0;
		for(i=1;i<=ret.degre;i++)
		{
		ret.coef[i] = (1.0/((double)i))*p.coef[i-1];
		}
	}
return ret;
}

/*Addition de p1 et p2*/	
polynome add(polynome p1,polynome p2)
{
int i,deg;
polynome p;

deg = maxint(p1.degre,p2.degre);
	if(p1.degre == p2.degre)
	{
		while(p1.coef[deg] == -p2.coef[deg])
		{
		deg--;
		}
	}	
new_pol(&p,deg);

	for(i=p.degre;i>=0;i--)
	{
		if(i>p1.degre)		p.coef[i] = p2.coef[i];
		else if(i>p2.degre)	p.coef[i] = p1.coef[i];
		else			p.coef[i] = p1.coef[i]+p2.coef[i];
	}
return p;
}

/*Calcul de p1 - p2*/
polynome diff(polynome p1,polynome p2)
{
oppose(p2.coef,p2.degre);
return(add(p1,p2));
} 

polynome mult(polynome p1,polynome p2)
{
polynome p;
	if(est_nul(p1) || est_nul(p2))
	{
	new_pol(&p,0);
	}
	else
	{
	int i,j;
	new_pol(&p,p1.degre + p2.degre);
		for(i=0;i<=p1.degre;i++)
		{
			for(j=0;j<=p2.degre;j++)
			{
			p.coef[i+j] += p1.coef[i] * p2.coef[j];
			}
		}
	}
return p;
}

/*Division de p1 par p2*/
void division_euc(polynome p1,polynome p2,polynome *pR,polynome *pQ)
{
    HWND hDlg;
    
	if(p1.degre<p2.degre)
	{
         new_pol(pQ,0);
	     copy(p1,pR);
	}
	else if(est_nul(p2))
	{
	     MessageBox(hDlg, "Division par 0", "Erreur", MB_OK | MB_ICONWARNING);
	}
	else
	{
	int n,rap,phdeg;
	polynome temp;
	
	phdeg = p1.degre;
	n=p1.degre - p2.degre;
	new_pol(pQ,n);
	copy(p1,pR);
		do
		{
		rap = pR->coef[phdeg]/p2.coef[p2.degre];
		new_pol(&temp,n);
		temp.coef[n] = rap;
		temp = mult(temp,p2);
		pQ->coef[n] = rap;
		*pR = diff(*pR,temp);
		n--;
		phdeg--;
		free_pol(&temp);
		}
		while(pR->degre>=p2.degre);
	}
}


->winmain.c

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "resource.h"

#define DB_OK 1


HINSTANCE hinst;
HWND hwnd, hEdit, hDlg;
WNDCLASSEX wc;
MSG msg;
int deg, q;
double *cf, *xe;

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
                                                LPSTR lpCmdLine, int nCmdShow)
{
    HACCEL haccel;

    hinst = hinstance;
    
    memset(&wc,0,sizeof(wc));

    wc.cbSize        = sizeof(wc);
    wc.style         = 0;
    wc.lpfnWndProc   = MainWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hinst;
    wc.hIcon         = LoadIcon(hinstance,IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = NULL;
    wc.lpszMenuName  =  "LEMENU";
    wc.lpszClassName = "MaWinClass";
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
		      MessageBox(NULL, "Erreur dans RegisterClassEx()", "Erreur!", MB_OK | MB_ICONERROR);
              return FALSE;
    }

    hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, "MaWinClass", "Polynômes", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 800, 575, NULL, NULL, hinstance, NULL);
    if (!hwnd)
    {
              MessageBox(NULL, "Impossible de créer la fenêtre principale", "Erreur!", MB_OK | MB_ICONERROR);
              return FALSE;
    }
    
    ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);

    haccel = LoadAccelerators(hinstance, "LesAccel");

    while (GetMessage(&msg, NULL, 0, 0) > 0)
    {
      if (!TranslateAccelerator(hwnd, haccel, &msg))
          {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
          }
    }
    return msg.wParam;
}
/******************************************************************************/

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static HFONT hFont;
    static HBRUSH EditBrush;
    static COLORREF BkEditcolor;
    static COLORREF TextColor = 0;
    static LOGFONT lf;
    static BOOL EditNotChg = TRUE;

    switch (uMsg)
    {
        case WM_CREATE:
        {
            
            hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "", WS_CHILD | WS_VISIBLE |
                                   ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL,
                                           0, 0, 0, 0, hwnd, NULL, hinst, NULL);

            SetClassLong(hEdit, GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_ARROW));
            wpOrigEditProc = (PVOID)SetWindowLong(hEdit, GWL_WNDPROC, (LONG)EditProc);
            
            ZeroMemory(&lf, sizeof(LOGFONT));
            lstrcpy(lf.lfFaceName,"Times New Roman");
            lf.lfHeight = 20;
            lf.lfItalic = TRUE;
            lf.lfWeight = FW_NORMAL;
            
            BkEditcolor = GetSysColor(COLOR_WINDOW);
            EditBrush = CreateSolidBrush(BkEditcolor);
            hFont = CreateFontIndirect(&lf);

            SendMessage(hEdit,WM_SETFONT,(UINT)hFont,TRUE);
            SendMessage(hEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(5, 5));

            return 0;
        }
        break;

        case WM_CLOSE:
            if(MessageBox(hwnd,"Etes vous sûr de vouloir fermer l'application ?"
                            ,"Question ?",MB_YESNO | MB_ICONQUESTION ) == IDYES)
                       PostQuitMessage(0);
            return 0;
        break;
            
        case WM_COMMAND:
            if (LOWORD(wParam) == IDM_EVAL || LOWORD(wParam) == IDM_DERIV || LOWORD(wParam) == IDM_INTEGR || LOWORD(wParam) == IDM_SOMME || LOWORD(wParam) == IDM_DIFF || LOWORD(wParam) == IDM_PROD || LOWORD(wParam) == IDM_DIV)
            {

                       MainWnd_Titre(hwnd, wParam);
                       MainWnd_Command(hinst, hEdit, wParam);

            }
            
            else if (LOWORD(wParam) == IDM_OPEN)
            {
                       OPENFILENAME ofn;
                       CHAR szFile[MAX_PATH] = {0};
                       ZeroMemory(&ofn, sizeof(OPENFILENAME));
#ifdef OPENFILENAME_SIZE_VERSION_400
                       ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
#else
                       ofn.lStructSize = sizeof(OPENFILENAME);
#endif
                       ofn.hwndOwner = hwnd;
                       ofn.lpstrFile = szFile;
                       ofn.nMaxFile = MAX_PATH;
                       ofn.lpstrFilter = "Fichiers Texte C\0*.txt\0\0";
                       ofn.nFilterIndex = 1;
                       ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
                       if (GetOpenFileName(&ofn)==TRUE)
                       {
                                HANDLE hf;
                                DWORD FileSize,nbcharRead ;
                                char *buffer;

                                hf = CreateFile(szFile, GENERIC_READ, 0,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
                                FileSize = GetFileSize(hf, NULL);
                                buffer = (char*)LocalAlloc(LMEM_FIXED, FileSize+1);
                                ReadFile(hf, buffer, FileSize, &nbcharRead, NULL) ;
                                buffer[FileSize] = 0;
                                SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)buffer);
                                LocalFree(buffer);
                                CloseHandle(hf);
                       }
                       else MessageBox(hwnd, "Impossible d'ouvrir le fichier", "Attention!", MB_OK | MB_ICONWARNING);
            }

            else if (LOWORD(wParam) == IDM_SAVE)
            {
                       OPENFILENAME ofn;
                       CHAR szFile[260]={0};

                       ZeroMemory(&ofn, sizeof(OPENFILENAME));
#ifdef OPENFILENAME_SIZE_VERSION_400
                       ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
#else
                       ofn.lStructSize = sizeof(OPENFILENAME);
#endif
                       ofn.hwndOwner = hwnd;
                       ofn.lpstrFile = szFile;
                       ofn.nMaxFile = sizeof(szFile);
                       ofn.lpstrFilter = "Fichiers Texte C\0*.txt\0\0";
                       ofn.nFilterIndex = 1;
                       ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
                       if (GetSaveFileName(&ofn)==TRUE)
                       {
                                HANDLE hf;
                                DWORD FileSize,nbcharRead ;
                                char *buffer;
                                FileSize = GetWindowTextLength(hEdit);
                                buffer = (char*)LocalAlloc(LMEM_FIXED, FileSize+1);
                                GetWindowText(hEdit, buffer, FileSize+1);
                                hf = CreateFile(szFile, GENERIC_WRITE, 0,NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
                                WriteFile(hf, buffer, FileSize, &nbcharRead, NULL) ;
                                CloseHandle(hf);
                                LocalFree(buffer);
                       }
                       else MessageBox(hwnd, "Impossible d'enregistrer le fichier", "Attention!", MB_OK | MB_ICONWARNING);
            }
          
            else if (LOWORD(wParam) == IDM_QUIT)
            {
                       if(MessageBox(hwnd,"Etes vous sûr de vouloir fermer l'application ?"
                            ,"Question ?",MB_YESNO | MB_ICONQUESTION ) == IDYES)
                            PostQuitMessage(0);
            }
            
            else if(LOWORD(wParam) == IDM_FONT)
            {
                       CHOOSEFONT cf;
                       ZeroMemory(&cf, sizeof(CHOOSEFONT));
                       cf.lStructSize = sizeof (CHOOSEFONT);
                       cf.hwndOwner = hwnd;
                       cf.lpLogFont = &lf;
                       cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;

                       if (ChooseFont(&cf))
                       {
                                DeleteObject(hFont);
                                hFont = CreateFontIndirect(&lf);
                                SendMessage(hEdit,WM_SETFONT,(UINT)hFont,TRUE);
                       }
            }
            else if(LOWORD(wParam) == IDM_TEXTCOLOR)
            {
                       CHOOSECOLOR cc;
                       static COLORREF acrCustClr[16];

                       ZeroMemory(&cc, sizeof(CHOOSECOLOR));
                       cc.lStructSize = sizeof(CHOOSECOLOR);
                       cc.hwndOwner = hwnd;
                       cc.lpCustColors = NULL;
                       cc.lpCustColors = (LPDWORD) acrCustClr;
                       cc.rgbResult = TextColor;
                       cc.Flags = CC_FULLOPEN | CC_RGBINIT;
                       if (ChooseColor(&cc)==TRUE)
                       {
                                TextColor = cc.rgbResult;
                                PostMessage(hEdit,WM_SETREDRAW,TRUE,0);
                       }
            }
            
            else if (LOWORD(wParam) == IDM_ABOUT)
                       DialogBox(hinst, "DIALOG1" , hwnd, (DLGPROC)Dialog1Proc);

            else if (HIWORD(wParam) == EN_CHANGE) EditNotChg = FALSE;

            return 0;
        break;
            
        case WM_CTLCOLOREDIT:
            if((HWND)lParam == hEdit)
            {
                SetTextColor((HDC)wParam, TextColor);
                SetBkColor((HDC)wParam, BkEditcolor);
                return EditBrush;
            }
        break;

        case WM_SIZE:
             MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
             return 0;
        break;

        case WM_DESTROY:
            DeleteObject(EditBrush);
            PostQuitMessage(0);
            return 0;
        break;

        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
/******************************************************************************/

LRESULT APIENTRY EditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   if (uMsg == WM_SETFOCUS || uMsg == WM_CONTEXTMENU || uMsg == WM_CHAR ||
                                                             uMsg == WM_KEYDOWN)
                                                                       return 0;
   return CallWindowProc(wpOrigEditProc, hwnd, uMsg, wParam, lParam);
}

/******************************************************************************/

BOOL APIENTRY Dialog1Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    switch (uMsg)
    {
      case WM_INITDIALOG:
      {
           return TRUE;
      }
      break;

      case WM_COMMAND:
      {
           if (LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDOK)
                {
                   EndDialog(hDlg,0);
                   return TRUE;
                }
      }
      break;

      default:
           return FALSE;
    }
}
/******************************************************************************/

BOOL APIENTRY Dialog2Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    switch (uMsg)
    {
      case WM_INITDIALOG:
      {
           SetFocus(GetDlgItem(hDlg, IDE_EDIT1));
           return FALSE;
      }
      break;

      case WM_COMMAND:
      {
           if (LOWORD(wParam) == IDOK)
           {
                deg = GetDlgItemInt(hDlg,IDE_EDIT1,NULL,TRUE);
                if (deg > 0)
                   EndDialog(hDlg, deg);
                else MessageBox(hDlg, "Valeur incorrecte", "Attention!", MB_OK | MB_ICONWARNING);
                   return TRUE;
           }
      }
      break;

      default:
         return FALSE;
    }
}
/******************************************************************************/
BOOL APIENTRY Dialog3Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    
    switch (uMsg)
    {
      case WM_INITDIALOG:
      {
           SetFocus(GetDlgItem(hDlg, IDE_EDIT2));
           return FALSE;
      }
      break;

      case WM_COMMAND:
      {
           if (LOWORD(wParam) == IDOK )
           {
                deg = GetDlgItemInt(hDlg,IDE_EDIT2,NULL,TRUE);
                if (deg > 0)
                   EndDialog(hDlg, deg);
                else MessageBox(hDlg, "Valeur incorrecte", "Attention!", MB_OK | MB_ICONWARNING);
                return TRUE;
           }
      }
      break;
         
      default:
         return FALSE;
    }
}

/******************************************************************************/
BOOL APIENTRY Dialog4Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    LOGFONT lf3;
    HFONT NewFont3, OldFont3;
    
    switch (uMsg)
    {
      case WM_INITDIALOG:
      {
           SetFocus(GetDlgItem(hDlg,IDE_EDIT3));
           return FALSE;
      }
      break;

      case WM_PAINT:
      {

           char st3[56];
           sprintf(st3, "Entrez le coefficient du terme de degré %d :", q);
           PAINTSTRUCT ps3;
           HDC hdc3 = BeginPaint(hDlg, &ps3);
           SetBkMode(hdc3, TRANSPARENT);
           
           ZeroMemory(&lf3, sizeof(LOGFONT));
           lstrcpy(lf3.lfFaceName,"MS Sans Serif");
           lf3.lfHeight = 8;
           lf3.lfItalic = FALSE;
           lf3.lfWeight = FW_NORMAL;

           NewFont3 = CreateFontIndirect(&lf3);
           OldFont3 = SelectObject(hdc3,NewFont3);
           TextOut(hdc3, 24, 18, st3 , lstrlen(st3));
           SelectObject(hdc3, OldFont3);
           DeleteObject(NewFont3);
           
           EndPaint(hDlg, &ps3);
           return FALSE;
      }
      break;
      
      case WM_COMMAND:
      {
           if (LOWORD(wParam) == IDOK )
           {
               
               char *string3;
               string3 = (char*)malloc(256*sizeof(char));
               cf = (double*)malloc(sizeof(double));

               GetDlgItemText(hDlg, IDE_EDIT3, string3, 256);
               *cf = atof(string3);
               EndDialog(hDlg, 0);
           }
           return TRUE;
      }
      break;
         
      default:
         return FALSE;
    }
}
/******************************************************************************/
BOOL APIENTRY Dialog5Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    switch (uMsg)
    {
      case WM_INITDIALOG:
      {
           SetFocus(GetDlgItem(hDlg,IDE_EDIT4));
           return FALSE;
      }
      break;

      case WM_COMMAND:
      {
           if (LOWORD(wParam) == IDOK )
           {
               
               char *string4;               
               string4 = (char*)malloc(256*sizeof(char));
               xe = (double*)malloc(sizeof(double));
               
               GetDlgItemText(hDlg, IDE_EDIT4, string4, 256);
               *xe = atof(string4);
               EndDialog(hDlg, 0);
           }
           return TRUE;
      }
      break;
         
      default:
         return FALSE;
    }
}

/******************************************************************************/

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

    double *coefs;
    coefs = (double*)malloc((deg+1)*sizeof(double));
    
	for(q=deg;q>=0;q--)
	{
         
      DialogBoxParam(hinst, "DIALOG4", hEdit, (DLGPROC)Dialog4Proc, (LPARAM)hEdit);
      
      coefs[q] = *cf;
      free(cf);

	}
	
	return coefs;
}

char *saisie_degre(HINSTANCE hinst, HWND hEdit, polynome *p, double *coefs, int deg, int nb_poly)
{
     int m = 0;
     char *szBuffer, *szBuffer1;
     szBuffer = (char*)malloc(256*sizeof(char));
     szBuffer1 = (char*)malloc(256*sizeof(char));
     p = (polynome*)malloc(2*sizeof(polynome));
     
     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);
     coefs = saisie_pol(hinst, hEdit, 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, 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_EVAL)
     {
           
           m = sprintf(buf, "Polynôme à évaluer:\r\n    %s", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0));
           DialogBoxParam(hinst, "DIALOG5", hEdit,(DLGPROC)Dialog5Proc, (LPARAM)hEdit);
           x = *xe;
           eval = eval_x(p[0],x);
           m += sprintf(buf + m, "\r\n\r\n    p1(%f) = %f", x, eval);
           free(xe);
     }
         
     else if (LOWORD(wParam) == IDM_DERIV)
     {

           m = sprintf(buf, "Polynôme à dériver:\r\n    %s", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0));
           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_INTEGR)
     {

           m += sprintf(buf + m, "Polynôme à intégrer:\r\n    %s", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0));
           tampon[0] = integre(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));
           m += sprintf(buf + m, "%s", saisie_degre(hinst, hEdit, &p[1], coefs, deg, 1));
           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);
     }
              
     else if (LOWORD(wParam) == IDM_DIFF)
     {
           
           m += sprintf(buf + m, "Polynômes à soustraire:\r\n    %s\r\n    ", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0));
           m += sprintf(buf + m, "%s", saisie_degre(hinst, hEdit, &p[1], coefs, deg, 1));
           tampon[0] = diff(p[0],p[1]);
           m += sprintf(buf + m, "\r\n\r\n    p1(x) - p2(x) = %s", afficher(&tampon[0], temp));
           free(temp);
     }
	          
     else if (LOWORD(wParam) == IDM_PROD)
     {

           m += sprintf(buf + m, "Polynômes à multiplier:\r\n    %s\r\n    ", saisie_degre(hinst, hEdit, &p[0], coefs, deg, 0));
           m += sprintf(buf + m, "%s", saisie_degre(hinst, hEdit, &p[1], coefs, deg, 1));
           tampon[0] = mult(p[0],p[1]);
           m += sprintf(buf + m, "\r\n\r\n    p1(x) * p2(x) = %s", afficher(&tampon[0], temp));
           free(temp);
     }
	          
     else if (LOWORD(wParam) == IDM_DIV)
     {

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

void MainWnd_Titre(HWND hwnd, WPARAM wParam)
{
     char *titre;
     
     titre = (char*)malloc(56*sizeof(char));
     
     GetWindowText(hwnd, titre, 56);
     free(titre);
     
     if (LOWORD(wParam) == IDM_EVAL)
          sprintf(titre, "EVALUATION D'UN POLYNOME");
     
     if (LOWORD(wParam) == IDM_DERIV)
          sprintf(titre, "DERIVATION D'UN POLYNOME");
     
     if (LOWORD(wParam) == IDM_INTEGR)
          sprintf(titre, "INTEGRATION D'UN POLYNOME");
     
     if (LOWORD(wParam) == IDM_SOMME)
          sprintf(titre, "SOMME DE DEUX POLYNOMES");
     
     if (LOWORD(wParam) == IDM_DIFF)
          sprintf(titre, "DIFFERENCE DE DEUX POLYNOMES");
     
     if (LOWORD(wParam) == IDM_PROD)
          sprintf(titre, "PRODUIT DE DEUX POLYNOMES");
     
     if (LOWORD(wParam) == IDM_DIV)
          sprintf(titre, "DIVISION EUCLIDIENNE DE DEUX POLYNOMES");
     
     SetWindowText(hwnd,titre);
     free(titre);
}


Le problème se pose au niveau de l'affichage du résultat, dans la fonction MainWnd_Command. Maintenant pour savoir si ça plante au niveau des sprintf ou au niveau de SetWindowText à la fin de la fonction, pas évident à savoir.
0