wazaki  | Bonjour, j'ai un examen de programmation C demain, et je n'arrive pas à corriger un exercice avc des listes chainées.
 C'est très simple normalement mais j'ai constamment une erreur sur la mise à jour du pointeur précédent.
  
  Code :
 - #include <stdio.h>
 - #include <stdlib.h>
 - #include <string.h>
 - #include <conio.h>
 - #define NB 3
 - /********** structure*/
 - typedef struct tabgroupes{
 - 	char tLibGrp[50];
 -    int tAgeMin;
 -    int tAgeMax;
 -    int tNbrInsc;
 -    struct liste *tPTRDebInsc;
 - }tabgroupes;
 - typedef struct liste{
 - 	char nomE[20];
 -    char prenomE[20];
 -    struct liste *pEnfSuiv;
 - }liste;
 - typedef struct fiche{
 -   char nomF[20];
 -    char prenomF[20];
 -    int ageF;
 - }fiche;
 - //********** prototype*/
 - void initabgroupes(tabgroupes []);
 - fiche obtention(void);
 - int rechtabgroupes(tabgroupes [], int);
 - void ajoutliste(tabgroupes [],int,fiche);
 - void imprimer(tabgroupes tab[]);
 - //********** fonction principale*/
 - void main(void)
 - {
 - 	tabgroupes tabgr[NB];
 -    fiche fiche;
 -    int indice;
 -    initabgroupes(tabgr);
 -    fiche = obtention();
 -    while(strcmp(fiche.nomF,"zzz" ))
 -    	{
 -        indice = rechtabgroupes(tabgr,fiche.ageF);
 -          ajoutliste(tabgr,indice,fiche);
 -        fiche = obtention();
 -       }
 -    imprimer(tabgr);
 -    getch();
 - }
 - //********** Fonctions associées*/
 - void initabgroupes(tabgroupes Tab[])
 - {
 - 	int i;
 -    char tlib[50];
 -    for(i=0;i<NB;i++)
 -    	{
 -        	printf("Entrez le libelle du groupe %d : ",i+1);
 -          scanf("%s",tlib);
 -          strcpy(Tab[i].tLibGrp,tlib);
 -          printf("Entrez l'age minimum de ce groupe: " );
 -          scanf("%d",&Tab[i].tAgeMin);
 -          printf("Entre l'age maximum de ce groupe: " );
 -          scanf("%d",&Tab[i].tAgeMax);
 -          Tab[i].tNbrInsc = 0;
 -        Tab[i].tPTRDebInsc = NULL;
 -       }
 -    clrscr();
 - }
 - fiche obtention()
 - {
 -    fiche fiche;
 -    printf("Entrez le nom de l'enfant: " );
 -    scanf("%s",fiche.nomF);
 -    printf("Entrez le prenom de l'enfant: " );
 -    scanf("%s",fiche.prenomF);
 -    printf("Entre l'age de l'enfant: " );
 -    scanf("%d",&fiche.ageF);
 -    clrscr();
 -    return fiche;
 - }
 - int rechtabgroupes(tabgroupes tab[], int ageF)
 - {
 - 	int i=0;
 -    while(ageF>tab[i].tAgeMax)
 -    	{
 -        i++;
 -       }
 -   return i;
 - }
 - void ajoutliste(tabgroupes tab[], int ind,fiche fiche)
 - {
 -    liste *ptr, *saveptr, *ptrnew;
 -    ptr = tab[ind].tPTRDebInsc;
 -    while(ptr != NULL && fiche.nomF>ptr->nomE)
 -    	{
 -        	saveptr = ptr;
 -          ptr=ptr->pEnfSuiv;
 -       }
 -       ptrnew = (liste *) malloc (sizeof(liste));
 -       if(ptrnew == NULL)
 -        {
 -          printf("Memoire full" );
 -          }
 -       else
 -        {
 -           strcpy(ptrnew->nomE,fiche.nomF);
 -           strcpy(ptrnew->prenomE,fiche.prenomF);
 -           ptrnew->pEnfSuiv = ptr;
 -           tab[ind].tNbrInsc ++;
 -           if(ptr==NULL)
 -            {
 -              tab[ind].tPTRDebInsc = ptrnew;
 -             }
 -           else
 -            {
 -                saveptr->pEnfSuiv = ptrnew;
 -             }
 -        }
 - }
 - void imprimer(tabgroupes tab[])
 - {
 -    liste *ptr;
 - 	int i;
 -    for(i=0;i<NB;i++)
 -    	{
 -        	ptr=tab[i].tPTRDebInsc;
 -          printf("Tableau %d\n",i+1);
 -          while(ptr != NULL)
 -          	{
 -              printf("%s\t%s\n",ptr->nomE,ptr->prenomE);
 -              	ptr=ptr->pEnfSuiv;
 -             }
 -       }
 - }
 
  |  
 
   dans la fonction "ajoutliste" dans le second else, c'est la que ce situe mon problème.   J'ai l'impression d'avoir fait ce qu'il faut mais cela échoue...
   A titre d'information je travaille sous borland 5.0
   Merci de m'aider (sans me renvoyer vers un site pr apprendre le C... )    |