Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
935 connectés 

  FORUM HardWare.fr
  Programmation

  je vous donne mon programme

 


 Mot :   Pseudo :  
 
 Page :   1  2
Page Précédente
Auteur Sujet :

je vous donne mon programme

n°437290
brash
voir signature!
Posté le 23-06-2003 à 13:43:57  profilanswer
 

mon progz de fin d'année, pour vous chers admirateurs. je vous aime mes fans, propagez mon programme à titre d'exemple d'excellence programatissimeuse, merci.  :jap:

mood
Publicité
Posté le 23-06-2003 à 13:43:57  profilanswer
 

n°437291
brash
voir signature!
Posté le 23-06-2003 à 13:44:12  profilanswer
 


# include <stdio.h>
# include <stdlib.h>
# include <alloc.h>
# include <string.h>
 
# define ENTR "c:\\etudiant\\entre.dat"
# define STA "c:\\etudiant\\stag.dat"
# define TEMP "c:\\etudiant\\temp.dat"
# define TMP "c:\\etudiant\\tmp.dat"
# define NB_SYNO 10
 
struct entreprise {
    int cle;
    char nom[25+1];
    char addresse[25+1];
    int codepost;
    char ville[25+1];
    char tel[20+1];
    char secteur[20+1];
                };
struct stagiaire
    {
    int cle;
    char nom[25+1];
    int cle_etr;
    char prenom[25+1];
    char addresse[25+1];
    int codepost;
    char ville[25+1];
    char tel[20+1];
    char tel_ent[20+1];
                };
struct liste_ent
    {
    int cle;
    char nom[25+1];
    int posi;
    struct liste_ent *suivant;
    };
struct liste_sta
    {
    int cle;
    char nom[25+1];
    int posi;
    struct liste_sta *suivant;
    };
struct ple_ent
   {
   int posi;
   struct ple_ent *suivant;
   };
struct ple_sta
   {
   int posi;
   struct ple_sta *suivant;
   };
struct temp
   {
   int cle_ent;
   int cle_sta;
   int posi_ent;
   int posi_sta;
   };
struct multi_ent_sect
    {
    char secteur[25+1];
    struct liste_ent *prem_ent;
    struct multi_ent_sect *suivant;
    };
struct multi_ent_sta
    {
    int cle_ent;
    struct liste_sta *prem_sta;
             struct multi_ent_sta *suivant;
    };
crea_temp();
add_ent(struct liste_ent**,struct multi_ent_sect**,struct ple_ent**);
add_sta(struct liste_sta** ,struct multi_ent_sta** ,struct liste_ent**,struct ple_sta**);
modif_sup_ent(struct liste_ent**,struct multi_ent_sect**,struct ple_ent**,struct multi_ent_sta**);
modif_sup_sta(struct liste_sta**,struct multi_ent_sta**,struct liste_ent**ind_nm_ent,struct ple_sta**);
modipent(struct liste_ent**,struct multi_ent_sect**,int);
modipsta(struct liste_sta**,struct multi_ent_sta**,struct liste_ent**ind_nm_ent,int);
afpent(struct entreprise*);
afpsta(struct stagiaire*);
aff_sec_ent();
aff_sec_sta();
afpent_ind(struct liste_ent*);
afpsta_ind(struct liste_sta*);
aff_sect_ent(struct multi_ent_sect*);
aff_sect_ent_spec(struct multi_ent_sect*);
afpent_sta(struct multi_ent_sta*);
afpent_sta_spec(struct multi_ent_sta*);
afpsta_sect(struct multi_ent_sect*,struct multi_ent_sta*);
afpsta_sect(struct multi_ent_sect*,struct multi_ent_sta*);
insert_ent(struct liste_ent**,int,char *,int);
insert_sta (struct liste_sta**,int,char *,int);
insert_multi_ent_sect(struct multi_ent_sect**,struct entreprise*,int);
insert_multi_ent_sta(struct multi_ent_sta**,struct stagiaire*,int);
new_ent (char * ,struct liste_ent **,int,struct liste_ent*,int );
new_sta (char * ,struct liste_sta **,int,struct liste_sta*,int );
seek_ent(struct liste_ent * ,char *,int []);
seek_sta(struct liste_sta *,char *,int []);
int seek_ent_sta(struct multi_ent_sta*,int);
del_ent(struct liste_ent**,int);
del_sta(struct liste_sta**,int);
del_multi_ent_sect(struct multi_ent_sect**,struct entreprise*,int);
del_ent_sta(struct multi_ent_sta**,int,int);
push_ent(struct ple_ent**,int);
push_sta(struct ple_sta**,int);
pop_ent(struct ple_ent**);
pop_sta(struct ple_sta**);
reorga(struct liste_ent**,struct liste_sta**,struct multi_ent_sect**,struct multi_ent_sta**,struct ple_ent**,struct ple_sta**);
compact(struct liste_ent**,struct liste_sta**,struct multi_ent_sect**,struct multi_ent_sta**,struct ple_ent**,struct ple_sta**);
 
main ()
{
struct ple_ent *pile_ent;
struct ple_sta *pile_sta;
struct liste_ent *ind_nm_ent;
struct liste_sta  *ind_nm_sta;
struct multi_ent_sect *ind_sect_ent;
struct multi_ent_sta *ind_ent_sta;
int rep1,rep2,rep3;
 
crea_temp();
ind_nm_ent=NULL;
ind_nm_sta=NULL;
ind_sect_ent=NULL;
ind_ent_sta=NULL;
pile_ent=NULL;
pile_sta=NULL;
reorga(&ind_nm_ent,&ind_nm_sta,&ind_sect_ent,&ind_ent_sta,&pile_ent,&pile_sta);
do{
  do{
 clrscr();
 printf("MENU PRINCIPAL\n" ) ;
 printf("1)Menu Ajout de fiches\n" );
 printf("2)Modification ou supression de fiches\n" );
 printf("3)Affichage de fiches\n" );
 printf("4)Fonction de compactage\n" );
 printf("5)Quitter" );
 fflush(stdin);
 scanf("%d",&rep1);
 }
  while(rep1<1 || rep1>5);
  switch (rep1)
 {
 case (1):
  {
  do {
   do {
    rep2=0;
    clrscr();
    printf("1)Ajout d'une entreprise\n" );
    printf("2)Ajout d'un  stagiaire\n" );
    printf("3)quitter" );
    fflush(stdin);
    scanf("%d",&rep2);
    }
   while(rep2<1 || rep2>3);
   switch (rep2)
    {
    case(1):
     {
     clrscr();
     add_ent(&ind_nm_ent,&ind_sect_ent,&pile_ent);
     break;
     }
    case(2):
     {
                    clrscr();
     add_sta(&ind_nm_sta,&ind_ent_sta,&ind_nm_ent,&pile_sta);
     break;
     }
    }
     }
  while (rep2!=3);
  break;
  }
 case(2):
  {
  do {
     do {
     rep2=0;
     clrscr();
     printf("1)Recherche d'une entreprise\n" );
     printf("2)Recherche d'un stagiaire\n" );
     printf("3)Quitter" );
     fflush(stdin);
     scanf("%d",&rep2);
     }
     while(rep2<1 || rep2>3);
     switch (rep2)
   {
   case (1):
    {
                clrscr ();
    modif_sup_ent(&ind_nm_ent,&ind_sect_ent,&pile_ent,&ind_ent_sta);
    break;
    }
   case (2):
    {
    clrscr ();
    modif_sup_sta(&ind_nm_sta,&ind_ent_sta,&ind_nm_ent,&pile_sta);
    break;
    }
   }
    }
  while(rep2!=3);
  break;
  }
 case (3):
  {
  do {
   do {
    rep2=0;
    clrscr();
    printf("1)Affichage des entreprises\n" );
    printf("2)Affichage des stagiaires\n" );
    printf("3)Quitter" );
    fflush(stdin);
    scanf("%d",&rep2);
    }
   while(rep2<1 || rep2>3);
   switch (rep2)
     {
     case(1):
      {
      do {
       do {
        rep3=0;
        clrscr();
        printf("1)Affichage sequentiel des entreprises\n" );
        printf("2)Affichage des entreprises triees par nom\n" );
        printf("3)Affichage des entreprises par secteur\n" );
        printf("4)Affichage des entreprises d'un secteur specifique\n" );
        printf("5)Quitter" );
        fflush(stdin);
        scanf("%d",&rep3);
        }
       while(rep3<1 || rep3>5);
       switch (rep3)
        {
        case(1):
          {
          aff_sec_ent();
          break;
          }
        case(2):
         {
         afpent_ind(ind_nm_ent);
         break;
         }
        case(3):
         {
         aff_sect_ent(ind_sect_ent);
         break;
         }
        case(4):
         {
         aff_sect_ent_spec(ind_sect_ent);
         break;
         }
        }
         }
      while (rep3!=5);
      break;
      }
     case(2):
      {
                        do {
       do {
        rep3=0;
        clrscr();
        printf("1)Affichage sequentiel des stagiaires\n" );
        printf("2)Affichage des stagiaires tries par nom\n" );
        printf("3)Affichage des stagiaires par entreprise\n" );
        printf("4)Affichage des stagiaires d'une entreprise specifique\n" );
        printf("5)Affichage des stagiaires par secteur\n" );
        printf("6)Affichage des stagiaires d'un secteur specique\n" );
        printf("7)quitter" );
        fflush(stdin);
        scanf("%d",&rep3);
        }
       while(rep3<1 || rep3>7);
       switch (rep3)
        {
        case(1):
         {
         aff_sec_sta();
         break;
          }
        case(2):
         {
         afpsta_ind(ind_nm_sta);
         break;
         }
        case(3):
         {
         afpent_sta(ind_ent_sta);
         break;
         }
                                case(4):
         {
         afpent_sta_spec(ind_ent_sta);
         break;
         }
        case(5):
         {
         afpsta_sect(ind_sect_ent,ind_ent_sta);
         break;
         }
        case(6):
         {
         afpsta_sect_spec(ind_sect_ent,ind_ent_sta);
         break;
         }
        }
       }
      while (rep3!=7);
      break;
      }
     }
  }
  while(rep2!=3);
 break;
 }
  case(4):
  {
  compact(&ind_nm_ent,&ind_nm_sta,&ind_sect_ent,&ind_ent_sta,&pile_ent,&pile_sta);
  break;
  }
  }
}
while (rep1!=5);
}
 
 
 
/****************FONCTION DE CREATION DU FICHIER TEMP***********************/
 
crea_temp()
{
FILE *ptemp;
int i;
struct temp tmp;
 
ptemp=fopen(TEMP,"r+b" );
if(!ptemp)
 {
 ptemp=fopen(TEMP,"wb" );
 tmp.cle_ent=0;
 tmp.cle_sta=0;
 tmp.posi_ent=0;
 tmp.posi_sta=0;
 fwrite(&tmp,sizeof(struct temp),1,ptemp);
 }
fclose(ptemp);
}
 
 
/*******************FONCTION D'AJOUT D'UN RECORD ENTTREPRISE***************/
 
add_ent(struct liste_ent **ind_nm_ent,struct multi_ent_sect **ind_sect_ent,struct ple_ent **pile_ent)
{
char essai[128],rep;
FILE *ptemp,*pent;
struct entreprise tmp;
struct temp tmp_temp;
do {
                clrscr();
 printf("\nEntrer le nom de l'entreprise:   " );
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer un nom de maximum 25 caracteres" );
 }
while (strlen(essai)>25);
strcpy(tmp.nom,essai);
do {
 printf("\nEntrer l'addresse de l'entreprise:   " );
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer une addresse de maximum 25 caracteres" );
 }
while (strlen(essai)>25);
strcpy(tmp.addresse,essai);
do {
 tmp.codepost=0;
 printf("\nEntrer le code postal de l'entreprise, celui-ci doit etre compris entre 1000 et 9999 inclus :   " );
 fflush(stdin);
 scanf("%d",&tmp.codepost);
 }
while(tmp.codepost <1000 ||tmp.codepost>9999);
do {
 printf("\nEntrer la ville de l'entreprise:   " );
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer une ville de maximum 25 caracteres" );
 }
while (strlen(essai)>25);
strcpy(tmp.ville,essai);
do {
 printf("\nEntrer le numéro de  téléphone de l'entreprise:   " );
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>20) printf("\nVous devez entrer un numero de telephone de maximum 20 caracteres" );
 }
while (strlen(essai)>20);
strcpy(tmp.tel,essai);
do {
 printf("\nEntrer le secteur d'activite de l'entreprise:   " );
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer un intitule de secteur de maximum 25 caracteres" );
 }
while (strlen(essai)>25);
strcpy(tmp.secteur,essai);
do
  {
  printf("Etes vous sur de vouloir ajouter cette fiche(o/n)?" );
  fflush(stdin);
  rep=getchar();
  rep=tolower(rep);
  }
while(rep!='o' && rep!='n');
if (rep=='o')
   {
   ptemp=fopen(TEMP,"r+b" );
   pent=fopen(ENTR,"r+b" );
   if (!pent) pent=fopen(ENTR,"wb" );
   fread(&tmp_temp,sizeof(struct temp),1,ptemp);
   tmp.cle=tmp_temp.cle_ent;
   if(*pile_ent==NULL)
   {
   fseek(pent,sizeof(struct entreprise)*tmp_temp.posi_ent,SEEK_SET);
   insert_ent(ind_nm_ent,tmp.cle,tmp.nom,tmp_temp.posi_ent);
   insert_multi_ent_sect(ind_sect_ent,&tmp,tmp_temp.posi_ent);
      tmp_temp.posi_ent++;
   }
   else
  {
  fseek(pent,sizeof(struct entreprise)* (*pile_ent)->posi,SEEK_SET);
  insert_ent(ind_nm_ent,tmp_temp.cle_ent,tmp.nom,(*pile_ent)->posi);
  insert_multi_ent_sect(ind_sect_ent,&tmp,(*pile_ent)->posi);
  pop_ent (pile_ent);
  }
   fwrite(&tmp,sizeof(struct entreprise),1,pent);
   fclose(pent);
   tmp_temp.cle_ent++;
   rewind(ptemp);
   fwrite(&tmp_temp,sizeof(struct temp),1,ptemp);
   fclose(ptemp);
   }
}
 
 
/***************************FONCTION D'AJOUT D'UN RECORD STAGIAIRE*******/
 
add_sta (struct liste_sta **ind_nm_sta,struct multi_ent_sta **ind_ent_sta,struct liste_ent **ind_nm_ent,struct ple_sta **pile_sta)
{
char essai[128],nomch[25+1],rep,rep2;
int vec[10],i;
FILE *ptemp,*psta,*pent;
struct stagiaire tmp;
struct temp tmp_temp;
struct entreprise tmp_ent;
 
if (*ind_nm_ent==NULL) {printf("Aucune entreprise existante, vous devez d'abord en entrer une!" );fflush(stdin);getch();}
else {
pent=fopen(ENTR,"r+b" );
do {
 printf("\nEntrer le nom du stagiaire:   " );
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer un nom de stagiaire de maximum 25 caracteres" );
 }
while (strlen(essai)>25);
strcpy(tmp.nom,essai);
do {
 printf("\nEntrer le prenom du stagiaire:   " );
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer un prenom de stagiaire de maximum 25 caractere" );
 }
while (strlen(essai)>25);
strcpy(tmp.prenom,essai);
do {
 printf("\nEntrer l'addresse du stagiaire:   " );
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer une addresse de stagiaire de maximum 25 caractere" );
 }
while (strlen(essai)>25);
strcpy(tmp.addresse,essai);
do {
   tmp.codepost=0;
   printf("\nEntrer le code postal du stagiaire,celui-ci doit etre entre 1000 et 9999 inclus:   " );
   fflush(stdin);
   scanf("%d",&tmp.codepost);
   }
while(tmp.codepost <1000 ||tmp.codepost>9999);
do {
 printf("\nEntrer la ville du stagiaire:   " );
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer une ville de maximum 25 caractere" );
 }
while (strlen(essai)>25);
strcpy(tmp.ville,essai);
do {
 printf("\nEntrer le numero de telephone prive du stagiaire:   " );
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>20) printf("\nVous devez entrer un numero de telephone de maximum 20 caractere" );
 }
while (strlen(essai)>20);
strcpy(tmp.tel,essai);
do {
 printf("\nEntrer le numero de telephone de l'entreprise du stagiaire:   " );
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>20) printf("\nVous devez entrer un numero de telephone de maximum 20 caractere" );
 }
while (strlen(essai)>20);
strcpy(tmp.tel_ent,essai);
do
   {
 printf ("\nEntrez le nom de l'entreprise cherchee: " );
 fflush (stdin);
 gets (nomch);
 seek_ent (*ind_nm_ent,nomch,vec);
 rep='x';
 i=0;
 if (vec[i]!=-1)
    {
    while (vec[i]!=-1 && rep!='O' && rep!='A')
    {
    rewind (pent);
    fseek (pent,vec[i]*sizeof(struct entreprise),SEEK_SET);
    fread(&tmp_ent,sizeof(struct entreprise),1,pent);
    clrscr();
    afpent(&tmp_ent);
    do {
    if(vec[i+1]!=-1) printf ("\nAppuier sur O pour mettre cette fiche N pour voir la fiche suivante  A pour Annuler: " );
    else printf ("\nAppuier sur O pour mettre cette fiche A pour Annuler: " );
    fflush (stdin);
    rep=getchar ();
    rep=toupper (rep);
    }
    while (rep!='A' &&  rep!='O' && rep!='N');
    if (rep=='O')
    {
    tmp.cle_etr=tmp_ent.cle;
    }
    i++;
    }
    }
  else
   {
   printf ("\nCe nom n'existe pas\n" );
   do {
    printf ("\nO pour rechercher une autre entreprise A pour Annuler: " );
    fflush (stdin);
    rep2=getchar ();
    rep2=toupper (rep2);
    }
   while (rep2!='A' &&  rep2!='O');
   }
 }
while (rep!='O' && rep2!='A');
if (rep=='O')
   {
 do
   {
   printf("Voulez etes sur de vouloir ajouter cette fiche(o/n)?" );
   fflush(stdin);
   rep=getchar();
   rep=tolower(rep);
   }
 while(rep!='o' && rep!='n');
   }
}
if(rep=='o')
  {
  ptemp=fopen(TEMP,"r+b" );
  psta=fopen(STA,"r+b" );
   if (!psta) psta=fopen(STA,"wb" );
  fread(&tmp_temp,sizeof(struct temp),1,ptemp);
  tmp.cle=tmp_temp.cle_sta;
  if(*pile_sta==NULL)
 {
 fseek(psta,sizeof(struct stagiaire)*tmp_temp.posi_sta,SEEK_SET);
 insert_sta(ind_nm_sta,tmp.cle,tmp.nom,tmp_temp.posi_sta);
 insert_multi_ent_sta(ind_ent_sta,&tmp,tmp_temp.posi_sta);
 tmp_temp.posi_sta++;
 }
  else
 {
 fseek(psta,sizeof(struct stagiaire)*(*pile_sta)->posi,SEEK_SET);
 insert_sta(ind_nm_sta,tmp.cle,tmp.nom,(*pile_sta)->posi);
 insert_multi_ent_sta(ind_ent_sta,&tmp,(*pile_sta)->posi);
 pop_sta (pile_sta);
 }
  fwrite(&tmp,sizeof(struct stagiaire),1,psta);
  tmp_temp.cle_sta++;
  rewind(ptemp);
  fwrite(&tmp_temp,sizeof(struct temp),1,ptemp);
  fclose(ptemp);
  fclose(psta);
  }
fclose(pent);
}
 
 
/******FONCTION DE MODIFICATION OU DE SUPRESSION D'UNE ENTREPRISE************/
 
modif_sup_ent(struct liste_ent **ind_nm_ent,struct multi_ent_sect **ind_sect_ent,struct ple_ent **pile_ent,struct multi_ent_sta **ind_ent_sta)
{
char essai[128],nomch[25+1],rep,rep2;
int vec[10],i,valid;
FILE *pent;
struct stagiaire tmp;
struct entreprise tmp_ent;
 
pent=fopen(ENTR,"r+b" );
printf ("Entrez le nom de l'entreprise  recherchee:   " );
fflush (stdin);
gets (nomch);
seek_ent (*ind_nm_ent,nomch,vec);
rep='x';
i=0;
if (vec[i]!=-1)
   {
 while (vec[i]!=-1  && rep!='A')
  {
  fseek (pent,vec[i]*sizeof(struct entreprise),SEEK_SET);
  fread(&tmp_ent,sizeof(struct entreprise),1,pent);
  clrscr();
  afpent(&tmp_ent);
  do {
   if(vec[i+1]!=-1) printf ("\n M pour Modifier \n S pour Suprimer \n A pour Annuler \n N pour Next: " );
   else printf ("\n M pour Modifier \n S pour Suprimer \n A pour Annuler: " );
   fflush (stdin);
   rep=getchar ();
   rep=toupper (rep);
   }
  while (rep!='A' && rep!='S' && rep!='M' && rep!='N');
  if (rep=='M')
   {
   modipent(ind_nm_ent,ind_sect_ent,vec[i]);
   }
   else
    {
    if (rep=='S')
     {
     valid=seek_ent_sta(*ind_ent_sta,tmp_ent.cle);
     if (valid==0)
      {
      del_ent (ind_nm_ent,vec[i]);
      del_multi_ent_sect(ind_sect_ent,&tmp_ent,vec[i]);
      tmp_ent.cle=-1;
      fseek (pent,vec[i]*sizeof(struct entreprise),SEEK_SET);
      fwrite(&tmp_ent,sizeof(struct entreprise),1,pent);
      push_ent (pile_ent,vec[i]);
      }
     else {printf("Vous devez supprimer les stagiaires de cette entreprise encore présent" );}
     }
     }
    i++;
  }
 }
 else { printf ("\nEntreprise non trouvee" );fflush (stdin); getch ();}
fclose(pent);
}
 
 
/******FONCTION DE MODIFICATION OU DE SUPRESSION D'UN STAGIAIRE**************/
 
modif_sup_sta(struct liste_sta **ind_nm_sta,struct multi_ent_sta **ind_ent_sta,struct liste_ent **ind_nm_ent,struct ple_sta **pile_sta)
{
char essai[128],nomch[25+1],rep,rep2;
int vec[10],i;
FILE *psta;
struct stagiaire tmp_sta;
 
psta=fopen(STA,"r+b" );
printf ("Entrez le nom du stagiaire recherche:   " );
fflush (stdin);
gets (nomch);
rep='x';
i=0;
seek_sta(*ind_nm_sta,nomch,vec);
if (vec[i]!=-1)
   {
 while (vec[i]!=-1  && rep!='A')
  {
  fseek (psta,vec[i]*sizeof(struct stagiaire),SEEK_SET);
  fread(&tmp_sta,sizeof(struct stagiaire),1,psta);
  clrscr();
  afpsta(&tmp_sta);
  do {
   if(vec[i+1]!=-1) printf ("\n  M pour Modifier\n S pour Suprimer \n A pour Annuler \n N pour Next: " );
   else printf ("\n  M pour Modifier \n S pour Suprimer \n A pour Annuler: " );
   fflush (stdin);
   rep=getchar ();
   rep=toupper (rep);
   }
  while (rep!='A' && rep!='S' && rep!='M' && rep!='N');
  if (rep=='M')
   {
   modipsta(ind_nm_sta,ind_ent_sta,ind_nm_ent,vec[i]);
   }
  else { if (rep=='S')
    {
    del_sta (ind_nm_sta,vec[i]);
    del_ent_sta(ind_ent_sta,tmp_sta.cle_etr,vec[i]);
    tmp_sta.cle=-1;
    fseek (psta,vec[i]*sizeof(struct stagiaire),SEEK_SET);
    fwrite(&tmp_sta,sizeof(struct stagiaire),1,psta);
    push_sta (pile_sta,vec[i]);
    }
     }
   i++;
   }
   }
  else { printf ("\nCe nom de stagiaire n'existe  pas!" );fflush (stdin); getch ();}
fclose(psta);
}
 
 
/*************FONCTION DE MODIFICATION D'UN RECORD ENTREPRISE*************/
 
modipent(struct liste_ent **ind_nm_ent,struct multi_ent_sect **ind_sect_ent,int posi)
{
char essai[128],rep;
struct entreprise tmp,old;
FILE *pent;
 
pent=fopen(ENTR,"r+b" );
fseek(pent,sizeof(struct entreprise)*posi,SEEK_SET);
fread(&tmp,sizeof(struct entreprise),1,pent);
fseek(pent,sizeof(struct entreprise)*posi,SEEK_SET);
fread(&old,sizeof(struct entreprise),1,pent);
do {
 printf("\nEntrer le nouveau nom de l'entreprise\n appuyez sur ENTER si vous voulez garder %s comme nom:   ",tmp.nom);
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer un nom d'entreprise de maximum 25 caractere" );
 }
while (strlen(essai)>25);
if (strlen(essai)!=0) strcpy(tmp.nom,essai);
do {
 printf("\nEntrer la nouvelle addresse de l'entreprise\n appuyez sur ENTER si vous voulez garder %s comme addresse:   ",tmp.addresse);
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer une addresse d'entreprise de maximum 25 caractere" );
 }
while (strlen(essai)>25);
if (strlen(essai)!=0) strcpy(tmp.addresse,essai);
do {
 tmp.codepost=0;
 printf("\nEntrer le code postal de l'entreprise, celui-ci doit etre compris entre 1000 et 9999 inclus:   " );
 fflush(stdin);
 scanf("%d",&tmp.codepost);
 }
while(tmp.codepost <1000 ||tmp.codepost>9999);
do {
 printf("\nEntrer la nouvelle ville de l'entreprise\n appuyez sur ENTER si vous voulez garder %s comme ville:   ",tmp.ville);
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\n\nVous devez entrer une ville de maximum 25 caracteres" );
 }
while (strlen(essai)>25);
if (strlen(essai)!=0) strcpy(tmp.ville,essai);
do {
 printf("\nEntrer le nouveau numero de telephone de l'entreprise\n appuyez sur ENTER si vous voulez garder %s comme telephone:   ",tmp.tel);
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>20) printf("\nVous devez entrer un numero de telephone de maximum 20 caracteres" );
 }
while (strlen(essai)>20);
if (strlen(essai)!=0) strcpy(tmp.tel,essai);
do {
 printf("\nEntrer le nouveau  secteur d'activite de l'entreprise\n appuyez sur ENTER si vous voulez garder %s comme secteur d'activite:   ",tmp.secteur);
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer un intitule de secteur de maximum 25 caracteres" );
 }
while (strlen(essai)>25);
if (strlen(essai)!=0) strcpy(tmp.secteur,essai);
do
  {
  printf("\n Etes vous sur de vouloir modifier cette fiche(o/n)?" );
  fflush(stdin);
  rep=getchar();
  rep=tolower(rep);
  }
while(rep!='o' && rep!='n');
if (rep=='o')
  {
  del_ent (ind_nm_ent,posi);
  del_multi_ent_sect(ind_sect_ent,&old,posi);
  fseek (pent,posi*sizeof(struct entreprise),SEEK_SET);
  fwrite(&tmp,sizeof(struct entreprise),1,pent);
  insert_ent(ind_nm_ent,tmp.cle,tmp.nom,posi);
  insert_multi_ent_sect(ind_sect_ent,&tmp,posi);
  }
fclose(pent);
}
 
 
/**************FONCTION DE MODIFICATION D'UN RECORD STAGIAIRE************/
 
modipsta(struct liste_sta**ind_nm_sta,struct multi_ent_sta **ind_ent_sta,struct liste_ent**ind_nm_ent,int posi)
{
char essai[128],nomch[128],rep,rep2;
int i,vec[NB_SYNO];
struct stagiaire tmp,old;
struct entreprise tmp_ent;
FILE *pent,*psta;
 
pent=fopen(ENTR,"rb" );
psta=fopen(STA,"r+b" );
fseek(psta,sizeof(struct stagiaire)*posi,SEEK_SET);
fread(&tmp,sizeof(struct stagiaire),1,psta);
fseek(psta,sizeof(struct stagiaire)*posi,SEEK_SET);
fread(&old,sizeof(struct stagiaire),1,psta);
do {
 printf("\Entrer le nom du stagiaire \n appuyez sur ENTER si vous voulez garder %s comme nom: ",tmp.nom);
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer un nom de stagiaire de maximum 25 caracteres" );
 }
while (strlen(essai)>25);
if (strlen(essai)!=0) strcpy(tmp.nom,essai);
do {
 printf("\nEntrer le prenom du stagiaire\n appuyez sur ENTER si vous voulez garder %s comme prenom: ",tmp.prenom);
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer un prenom de stagiaire de maximum 25 caractere" );
 }
while (strlen(essai)>25);
if (strlen(essai)!=0) strcpy(tmp.prenom,essai);
do {
 printf("\nEntrer l'addresse du stagiaire\n appuyez sur  ENTER si vous voulez garder %s comme addresse: ",tmp.addresse);
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer une addresse de stagiaire de maximum 25 caracteres" );
 }
while (strlen(essai)>25);
if (strlen(essai)!=0) strcpy(tmp.addresse,essai);
do {
   tmp.codepost=0;
   printf("\nEntrer le code postal du stagiaire,celui-ci doit etre entre 1000 et 9999 inclus:   " );
   fflush(stdin);
   scanf("%d",&tmp.codepost);
   }
while(tmp.codepost <1000 ||tmp.codepost>9999);
do {
 printf("\nEntrer la ville du stagiaire\n appuyez ENTER si vous voulez garder %s comme ville: ",tmp.ville);
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>25) printf("\nVous devez entrer une ville de maximum 25 caractere" );
 }
while (strlen(essai)>25);
if (strlen(essai)!=0) strcpy(tmp.ville,essai);
do {
 printf("\nEntrer le numero de telephone prive du stagiaire\n appuyez sur ENTER si vous voulez garder %s comme telephone: ",tmp.tel);
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>20) printf("\nVous devez entrer un numero de telephone de maximum 20 caractere" );
 }
while (strlen(essai)>20);
if (strlen(essai)!=0) strcpy(tmp.tel,essai);
do {
 printf("\nEntrer le numero de telephone de l'entreprise du stagiaire\n appuyez sur ENTER si vous voulez garder %s comme telephone: ",tmp.tel_ent);
 fflush(stdin);
 gets(essai);
 if (strlen(essai)>20) printf("\nVous devez entrer un numero de telephone de maximum 20 caractere" );
 }
while (strlen(essai)>20);
if (strlen(essai)!=0) strcpy(tmp.tel_ent,essai);
do
   {
 printf ("\nEntrez le nom de l'entreprise cherchee:   " );
 fflush (stdin);
 gets (nomch);
 seek_ent (*ind_nm_ent,nomch,vec);
 rep='x';
 i=0;
 if (vec[i]!=-1)
    {
    while (vec[i]!=-1 && rep!='O' && rep!='A')
    {
    fseek (pent,vec[i]*sizeof(struct entreprise),SEEK_SET);
    fread(&tmp_ent,sizeof(struct entreprise),1,pent);
    clrscr();
    afpent(&tmp_ent);
    do {
    if(vec[i+1]!=-1) printf ("\n O pour mettre cette fiche\n N pour voir la fiche suivante \n A pour Annuler: " );
    else printf ("\n O pour mettre cette fiche\n A pour Annuler: " );
    fflush (stdin);
    rep=getchar ();
    rep=toupper (rep);
    }
    while (rep!='A' &&  rep!='O' && rep!='N');
    if (rep=='O')
    {
    tmp.cle_etr=tmp_ent.cle;
    }
    i++;
    }
    }
  else
   {
   printf ("\nCe nom n'existe pas\n" );
   do {
    printf ("\n O pour rechercher une autre entreprise \n A pour Annuler: " );
    fflush (stdin);
    rep2=getchar ();
    rep2=toupper (rep2);
    }
   while (rep2!='A' &&  rep2!='O');
   }
 }
while (rep!='O' && rep2!='A');
if (rep=='O')
   {
 do
   {
   printf("Etes vous sur de vouloir modifier cette fiche(o/n)?" );
   fflush(stdin);
   rep=getchar();
   rep=tolower(rep);
   }
 while(rep!='o' && rep!='n');
   }
if (rep=='o')
  {
  del_sta (ind_nm_sta,posi);
  del_ent_sta(ind_ent_sta,old.cle_etr,posi);
  fseek (psta,posi*sizeof(struct stagiaire),SEEK_SET);
  fwrite(&tmp,sizeof(struct stagiaire),1,psta);
  insert_sta(ind_nm_sta,tmp.cle,tmp.nom,posi);
  insert_multi_ent_sta(ind_ent_sta,&tmp,posi);
  }
fclose(pent);
fclose(psta);
}
 
/*************FONCTION DE VISUALISATION D'UN RECORD ENTREPRISE*************/
 
afpent(struct entreprise* fiche)
{
printf("\nCle   : %d",fiche->cle);
printf("\nNom   : %s",fiche->nom);
printf("\nAddresse   : %s",fiche->addresse);
printf("\nCode postale   : %d",fiche->codepost);
printf("\nVille   : %s",fiche->ville);
printf("\nTelephone   : %s",fiche->tel);
printf("\nSecteur   : %s",fiche->secteur);
}
 
 
/*************FONCTION DE VISUALISATION D'UN RECORD STAGIAIRE***************/
 
afpsta(struct stagiaire* fiche)
{
printf("Cle   : %d",fiche->cle);
printf("\nNom   : %s",fiche->nom);
printf("\nCle etrangere   : %d",fiche->cle_etr);
printf("\nPrenom    : %s",fiche->prenom);
printf("\nAddresse   : %s",fiche->addresse);
printf("\nCode postale   : %d",fiche->codepost);
printf("\nVille   : %s",fiche->ville);
printf("\nTelephone prive   : %s",fiche->tel);
printf("\nTelephone de l'entreprise   : %s",fiche->tel_ent);
}
 
 
/*********FONCTION DE VISUALISATION SEQUENTIELLE DU FICHIER ENTREPRISE******/
 
aff_sec_ent ()
{
FILE *f1;
struct entreprise tmp;
 
f1=fopen(ENTR,"rb" );
while(fread(&tmp,sizeof(struct entreprise),1,f1))
{
if(tmp.cle!=-1)
 {
 clrscr();
 afpent(&tmp);
 fflush(stdin);
 getch();
 }
}
}
/********FONCTION DE VISUALISATION SEQUENTIELLE DU FICHIER STAGIAIRE********/
 
aff_sec_sta ()
{
FILE *f1;
struct stagiaire tmp;
 
f1=fopen(STA,"rb" );
while(fread(&tmp,sizeof(struct stagiaire),1,f1))
{
if(tmp.cle!=-1)
 {
    clrscr();
 afpsta(&tmp);
 fflush(stdin);
 getch();
 }
}
}
 
 
/****FONCTION DE VISUALISATION DES RECORDS ENTREPRISE INDEXE SUR LE NOM*****/
 
afpent_ind(struct liste_ent* index)
{
struct entreprise tmp;
FILE* f1;
 
f1=fopen(ENTR,"rb" );
while(index!=NULL)
   {
 clrscr();
 fseek(f1,sizeof(struct entreprise)*index->posi,SEEK_SET);
 fread(&tmp,sizeof(struct entreprise),1,f1);
 afpent(&tmp);
 fflush(stdin);
 getch();
 index=index->suivant;
 }
}
 
 
/*****FONCTION DE VISUALISATION DES RECORDS STAGIAIRE INDEXE SUR LE NOM****/
 
afpsta_ind(struct liste_sta* index)
{
struct stagiaire tmp;
FILE *f1;
 
f1=fopen(STA,"rb" );
while(index!=NULL)
 {
 clrscr();
 fseek(f1,sizeof(struct stagiaire)*index->posi,SEEK_SET);
 fread(&tmp,sizeof(struct stagiaire),1,f1);
 afpsta(&tmp);
 fflush(stdin);
 getch();
 index=index->suivant;
 }
}
 
/******FONCTION DE VISUALISATION DES RECORDS ENTREPRISE INDEXE SUR LE SECTEUR*/
 
aff_sect_ent(struct multi_ent_sect* index)
{
struct entreprise tmp;
struct liste_ent *ss_ind;
FILE* f1;
 
f1=fopen(ENTR,"rb" );
while(index!=NULL)
   {
   ss_ind=index->prem_ent;
   while(ss_ind!=NULL)
  {
  clrscr();
  fseek(f1,sizeof(struct entreprise)*ss_ind->posi,SEEK_SET);
  fread(&tmp,sizeof(struct entreprise),1,f1);
  printf("\nintitule du secteur:    %s\n",tmp.secteur);
  afpent(&tmp);
  fflush(stdin);
  getch();
  ss_ind=ss_ind->suivant;
  }
 index=index->suivant;
 }
}
 
 
/***FONCTION DE VISUALISATION DES RECORDS ENTREPRISE D'UN SECTEUR SPECIFIQUE**/
 
aff_sect_ent_spec(struct multi_ent_sect* index)
{
char secteur[25+1];
struct entreprise tmp;
struct liste_ent *ss_ind;
FILE* f1;
 
f1=fopen(ENTR,"rb" );
printf("\nEntrez le nom du secteur rechercher:   " );
fflush(stdin);
gets(secteur);
while((strcmp(index->secteur,secteur))<0 && index!=NULL)
   {
   index=index->suivant;
 }
if ((strcmp(index->secteur,secteur))==0)
 {
 ss_ind=index->prem_ent;
 while (ss_ind!=NULL)
  {
        clrscr();
  fseek(f1,sizeof(struct entreprise)*ss_ind->posi,SEEK_SET);
  fread(&tmp,sizeof(struct entreprise),1,f1);
  printf("\nintitule du secteur:    %s\n",tmp.secteur);
  afpent(&tmp);
  fflush(stdin);
  getch();
  ss_ind=ss_ind->suivant;
  }
 }
else
 {
 printf("\naucune entreprise appartenant a ce secteur" );
 fflush(stdin);
 getch();
 }
}
 
 
/**FONCTION DE VISUALISATION DES RECORDS STAGIAIRE INDEXE SUR L'ENTREPRISE*/
 
afpent_sta(struct multi_ent_sta* index)
{
struct stagiaire tmp;
struct liste_sta *ss_ind;
FILE*f1;
 
f1=fopen(STA,"rb" );
while(index!=NULL)
   {
   ss_ind=index->prem_sta;
   while(ss_ind!=NULL)
  {
  clrscr();
  fseek(f1,sizeof(struct stagiaire)*ss_ind->posi,SEEK_SET);
  fread(&tmp,sizeof(struct stagiaire),1,f1);
  printf("\nentreprise numero:    %d\n",tmp.cle_etr);
  afpsta(&tmp);
  fflush(stdin);
  getch();
  ss_ind=ss_ind->suivant;
  }
 index=index->suivant;
 }
}
 
 
/*FONCTION DE VISUALISATION DES RECORDS STAGIAIRE D'UNE ENTREPRISE SPECIFIQUE*/
 
afpent_sta_spec(struct multi_ent_sta* index)
{
int cle;
struct stagiaire tmp;
struct liste_sta *ss_ind;
FILE*f1;
 
f1=fopen(STA,"rb" );
printf("\nEntrez la cle de l'entreprise:    " );
scanf("%d",&cle);
while(index->cle_ent<cle && index!=NULL)
   {
   index=index->suivant;
   }
if (cle==index->cle_ent)
   {
   ss_ind=index->prem_sta;
   while(ss_ind!=NULL)
  {
  clrscr();
  fseek(f1,sizeof(struct stagiaire)*ss_ind->posi,SEEK_SET);
  fread(&tmp,sizeof(struct stagiaire),1,f1);
  printf("\nnumero d'entreprise:   %d\n",tmp.cle_etr);
  afpsta(&tmp);
  fflush(stdin);
  getch();
  ss_ind=ss_ind->suivant;
  }
 }
else
 {
 printf("\nCette entreprise n'a aucun stagiaire ou n'existe pas" );
 fflush(stdin);
 getch();
 }
}
 
 
/*******FONCTION D'AFFICHAGE DES STAGIAIRE PAR SECTEUR****************/
 
afpsta_sect(struct multi_ent_sect*ind_sect,struct multi_ent_sta*ind_ent_sta)
{
struct multi_ent_sta *tmp;
struct stagiaire stag;
struct liste_ent *ss_ind_ent;
struct liste_sta *ss_ind_sta;
FILE *f1;
 
f1=fopen(STA,"rb" );
while (ind_sect!=NULL)
 {
 ss_ind_ent=ind_sect->prem_ent;
 while (ss_ind_ent!=NULL)
  {
  tmp=ind_ent_sta;
  while(tmp->cle_ent!=ss_ind_ent->cle && tmp!=NULL)
   {
   tmp=tmp->suivant;
   }
  if (tmp!=NULL)
   {
   ss_ind_sta=tmp->prem_sta;
   while(ss_ind_sta!=NULL)
    {
    fseek(f1,sizeof(struct stagiaire)*ss_ind_sta->posi,SEEK_SET);
    fread(&stag,sizeof(struct stagiaire),1,f1);
    clrscr();
    printf("\nintitule du secteur:   %s\n",ind_sect->secteur);
    afpsta(&stag);
    fflush(stdin);
    getch();
    ss_ind_sta=ss_ind_sta->suivant;
    }
   }
  ss_ind_ent=ss_ind_ent->suivant;
  }
 ind_sect=ind_sect->suivant;
 }
}
 
/******FONCTION D'AFFICHAGE DES STAGIAIRE D'UN SECTEUR SPECIFIQUE**********/
 
afpsta_sect_spec(struct multi_ent_sect*ind_sect,struct multi_ent_sta*ind_ent_sta)
{
char secteur[25];
struct multi_ent_sta *tmp;
struct stagiaire stag;
struct liste_ent *ss_ind_ent;
struct liste_sta *ss_ind_sta;
FILE *f1;
 
f1=fopen(STA,"rb" );
printf("\nEntrer le nom du secteur recherchee:   " );
fflush(stdin);
gets(secteur);
while (strcmp(ind_sect->secteur,secteur)<0)
 {
 ind_sect=ind_sect->suivant;
 }
if(strcmp(ind_sect->secteur,secteur)==0)
 {
 ss_ind_ent=ind_sect->prem_ent;
 while (ss_ind_ent!=NULL)
  {
  tmp=ind_ent_sta;
  while(tmp->cle_ent!=ss_ind_ent->cle && tmp!=NULL)
   {
   tmp=tmp->suivant;
   }
  if (tmp!=NULL)
   {
   ss_ind_sta=tmp->prem_sta;
   while(ss_ind_sta!=NULL)
    {
    fseek(f1,sizeof(struct stagiaire)*ss_ind_sta->posi,SEEK_SET);
    fread(&stag,sizeof(struct stagiaire),1,f1);
    clrscr();
    printf("\nintitule du secteur:   %s\n",ind_sect->secteur);
    afpsta(&stag);
    fflush(stdin);
    getch();
    ss_ind_sta=ss_ind_sta->suivant;
    }
   }
  ss_ind_ent=ss_ind_ent->suivant;
  }
 }
else
 {
 printf("\naucun stagiaire appartenant a ce secteur" );
 fflush(stdin);
 getch();
 }
}
 
/********FONCTION D'INSERTION D'UN RECORD ENTREPRISE DANS LA LISTE**********/
 
insert_ent(struct liste_ent **racine,int cle,char *nom,int posi)
{
int essai;
struct liste_ent *p_prest,*p_old;
 
if (*racine==NULL || strcmp (nom,(*racine)->nom)<0)
 {
 new_ent (nom,racine,cle,*racine,posi);
 }
else
 {
 p_prest=(*racine)->suivant;
 p_old=*racine;
 while (p_prest!=NULL && strcmp (nom,p_prest->nom)>0)
   {
   p_old=p_prest;
   p_prest=p_prest->suivant;
   }
 new_ent (nom,&p_old->suivant,cle,p_prest,posi);
 }
}
 
 
/********FONCTION D'INSERTION D'UN RECORD STAGIAIRE DANS LA LISTE**********/
 
insert_sta (struct liste_sta **racine,int cle,char *nom,int posi)
{
struct liste_sta *p_prest,*p_old;
 
if (*racine==NULL || strcmp (nom,(*racine)->nom)<0)
 {
 new_sta (nom,racine,cle,*racine,posi);
 }
else
 {
 p_prest=(*racine)->suivant;
 p_old=*racine;
 while (p_prest!=NULL && strcmp (nom,p_prest->nom)>0)
   {
   p_old=p_prest;
   p_prest=p_prest->suivant;
   }
 new_sta (nom,&p_old->suivant,cle,p_prest,posi);
 }
}
 
 
/*FONCTION D'INSERTION D'UN RECORD ENTREPRISE DANS LA MULTILISTE SECTEUR*/
 
insert_multi_ent_sect(struct multi_ent_sect**racine,struct entreprise* tmp,int posi)
{
struct multi_ent_sect *p_prest,*p_old;
 
if (*racine==NULL || strcmp (tmp->secteur,(*racine)->secteur)<0)
   {
   new_multi_ent_sect(tmp,racine,*racine,posi);
   }
else {
  if (strcmp (tmp->secteur,(*racine)->secteur)==0)
  {
  insert_ent(&(*racine)->prem_ent,tmp->cle,tmp->nom,posi);
  }
  else {
    p_prest=(*racine)->suivant;
    p_old=*racine;
    while (p_prest!=NULL && strcmp (tmp->secteur,p_prest->secteur)>0)
   {
            p_old=p_prest;
   p_prest=p_prest->suivant;
   }
    if (strcmp (tmp->secteur,(p_prest)->secteur)==0)
   {
   insert_ent(&p_prest->prem_ent,tmp->cle,tmp->nom,posi);
   }
    else {
      new_multi_ent_sect(tmp,&p_old->suivant,p_prest,posi);
      }
    }
  }
}
 
 
/***FONCTION D'INSERTION D'UN RECORD STAGIAIRE DANS LA MULTILISTE SECTEUR*/
 
insert_multi_ent_sta(struct multi_ent_sta**racine,struct stagiaire* tmp,int posi)
{
struct multi_ent_sta *p_prest,*p_old;
 
if (*racine==NULL || tmp->cle_etr<(*racine)->cle_ent)
   {
   new_multi_ent_sta(tmp,racine,*racine,posi);
   }
else {
  if ((tmp)->cle_etr==(*racine)->cle_ent)
  {
  insert_sta(&(*racine)->prem_sta,tmp->cle,tmp->nom,posi);
  }
  else {
    p_prest=(*racine)->suivant;
    p_old=*racine;
    while (p_prest!=NULL && tmp->cle_etr > p_prest->cle_ent)
   {
            p_old=p_prest;
   p_prest=p_prest->suivant;
   }
    if (tmp->cle_etr==(p_prest)->cle_ent)
   {
   insert_sta(&p_prest->prem_sta,tmp->cle,tmp->nom,posi);
   }
    else {
      new_multi_ent_sta(tmp,&p_old->suivant,p_prest,posi);
      }
    }
  }
}
 
 
/*******FONCTION D'AJOUT D'UN RECORD ENTREPRISE DANS LA LISTE**********/
 
new_ent (char * nom,struct liste_ent **p_old,int cle,struct liste_ent* p_next,int posi)
{
struct liste_ent *new;
 
new=malloc (sizeof(struct liste_ent));
strcpy (new->nom,nom);
new->suivant=p_next;
new->cle=cle;
new->posi=posi;
*p_old=new;
}
 
 
/************FONCTION D'AJOUT D'UN RECORD STAGIAIRE DANS LA LISTE*********/
 
new_sta (char * nom,struct liste_sta **p_old,int cle,struct liste_sta* p_next,int posi)
{
struct liste_sta *new;
 
new=malloc (sizeof(struct liste_sta));
strcpy (new->nom,nom);
new->suivant=p_next;
new->cle=cle;
new->posi=posi;
*p_old=new;
}
 
 
/******FONCTION D'AJOUT D'UN RECORD ENTREPRISE DANS LA MULTI LISTE********/
 
new_multi_ent_sect (struct entreprise *tmp,struct multi_ent_sect **p_old,struct multi_ent_sect* p_next,int posi)
{
struct multi_ent_sect *new;
 
new=malloc (sizeof(struct multi_ent_sect));
strcpy (new->secteur,tmp->secteur);
*p_old=new;
new->suivant=p_next;
new->prem_ent=NULL;
insert_ent(&new->prem_ent,tmp->cle,tmp->nom,posi);
}
 
 
/******FONCTION D'AJOUT D'UN RECORD STAGIAIRE DANS LA MULTI LISTE*********/
 
new_multi_ent_sta (struct stagiaire *tmp,struct multi_ent_sta **p_old,struct multi_ent_sta* p_next,int posi)
{
struct multi_ent_sta *new;
 
new=malloc (sizeof(struct multi_ent_sta));
new->cle_ent=tmp->cle_etr;
*p_old=new;
new->suivant=p_next;
new->prem_sta=NULL;
insert_sta(&new->prem_sta,tmp->cle,tmp->nom,posi);
}
 
 
/******FONCTION DE RECHERCHE D'UN RECORD ENTREPRISE BASE SUR LE NOM********/
 
seek_ent(struct liste_ent * index ,char *nomch,int vec [NB_SYNO])
{
int i=0;
 
while (index!=NULL && strcmp(nomch,index->nom)>=0 )
  {
  if (strcmp(nomch,index->nom)==0)
   {
   vec[i]=(index)->posi;
            index=index->suivant;
   i++;
   }
  else index=index->suivant;
  }
vec[i]=-1;
}
 
 
/*******FONCTION DE RECHERCHE D'UN RECORD STAGIARE BASE SUR LE NOM*******/
 
seek_sta(struct liste_sta * index ,char *nomch,int vec [NB_SYNO])
{
int i=0;
 
while (index!=NULL && strcmp(nomch,index->nom)>=0 )
  {
  if (strcmp(nomch,index->nom)==0)
   {
   vec[i]=(index)->posi;
            index=index->suivant;
   i++;
   }
  else index=index->suivant;
  }
vec[i]=-1;
}
/***FONCTION DE RECHERCHE D'UN RECORD ENTREPRISE DANS LA MULTI-LISTE*******/
 
int seek_ent_sta(struct multi_ent_sta* index,int cle)
{
int valid=1;
 
while (index!=NULL && cle<index->cle_ent)
  {
  index=index->suivant;
  }
if (cle==index->cle_ent|| index->prem_sta==NULL)valid=0;
return valid;
}
 
 
/******FONCTION DE SUPPRESION D'UN RECORD ENTREPRISE DANS LA LISTE**********/
 
del_ent (struct liste_ent **racine,int  a_sup)
{
struct liste_ent *p_prest,*p_old;
 
if (a_sup==(*racine)->posi)
 {
 free (*racine);
 *racine=(*racine)->suivant;
  }
else
 {
 p_prest=(*racine)->suivant;
 p_old=*racine;
 while (a_sup!=p_prest->posi)
   {
   p_old=p_prest;
   p_prest=p_prest->suivant;
   }
 
 p_old->suivant=p_prest->suivant;
 free (p_prest);
 }
}
 
 
/********FONCTION DE SUPPRESSION D'UN RECORD STAGIAIRE DANS LA LISTE********/
 
del_sta (struct liste_sta **racine,int  a_sup)
{
struct liste_sta *p_prest,*p_old;
 
if (a_sup==(*racine)->posi)
 {
 free (*racine);
 *racine=(*racine)->suivant;
  }
else
 {
 p_prest=(*racine)->suivant;
 p_old=*racine;
 while (a_sup!=p_prest->posi)
   {
   p_old=p_prest;
   p_prest=p_prest->suivant;
   }
 
 p_old->suivant=p_prest->suivant;
 free (p_prest);
 }
}
 
 
 
/*FONCTION DE SUPPRESION D'UN RECORD ENTREPRISE DANS LA MULTI-LISTE BASE SUR LE SECTEUR*/
 
del_multi_ent_sect(struct multi_ent_sect** index,struct entreprise*tmp,int posi)
{
struct multi_ent_sect *p_prest,*p_old;
 
if (strcmp((*index)->secteur,tmp->secteur)==0)
 {
 del_ent(&(*index)->prem_ent,posi);
 if ((*index)->prem_ent==NULL)
    {
    free (*index);
    *index=(*index)->suivant;
    }
 }
else
 {
 p_prest=(*index)->suivant;
 p_old=*index;
 while (strcmp(p_prest->secteur,tmp->secteur)!=0)
   {
   p_old=p_prest;
   p_prest=p_prest->suivant;
   }
 del_ent(&(p_prest->prem_ent),posi);
 if (p_prest->prem_ent==NULL)
  {
 p_old->suivant=p_prest->suivant;
 free (p_prest);
  }
 }
}
 
 
/*FONCTION DE SUPPRESION D'UN RECORD STAGIARE DANS LA MULTI-LISTE BASE SUR LES ENTREPRISE*/
 
del_ent_sta(struct multi_ent_sta** index,int cle_etr,int posi)
{
struct multi_ent_sta *p_prest,*p_old;
 
if ((*index)->cle_ent==cle_etr)
 {
 del_sta(&(*index)->prem_sta,posi);
 if ((*index)->prem_sta==NULL)
    {
    free (*index);
    *index=(*index)->suivant;
    }
 }
else
 {
 p_prest=(*index)->suivant;
 p_old=*index;
 while (p_prest->cle_ent!=cle_etr)
   {
   p_old=p_prest;
   p_prest=p_prest->suivant;
   }
 del_sta(&(p_prest->prem_sta),posi);
 if (p_prest->prem_sta==NULL)
  {
 p_old->suivant=p_prest->suivant;
 free (p_prest);
  }
 }
}
 
/*******FONCTION D'AJOUT D'UN ELEMENT DANS LA PILE ENTREPRISE************/
 
push_ent (struct ple_ent **p_sup,int posi)
{
struct ple_ent *new;
 
new=malloc (sizeof(struct ple_ent));
new->suivant=(*p_sup);
new->posi=posi;
*p_sup=new;
}
 
 
/********FONCTION D'AJOUT D'UN ELEMENT DANS LA PILE ENTREPRISE************/
 
push_sta (struct ple_sta **p_sup,int posi)
{
struct ple_sta *new;
 
new=malloc (sizeof(struct ple_sta));
new->suivant=(*p_sup);
new->posi=posi;
*p_sup=new;
}
 
 
/********FONCTION DE SUPPRESION D'UN ELEMENT DE LA PILE ENTREPRISE********/
 
pop_ent (struct ple_ent **p_sup)
{
struct ple_ent *tmp;
tmp=(*p_sup)->suivant;
free (*p_sup);
*p_sup=tmp;
}
 
 
pop_sta (struct ple_sta **p_sup)
{
struct ple_sta *tmp;
tmp=(*p_sup)->suivant;
free (*p_sup);
*p_sup=tmp;
}
 
/**********FONCTION DE REORGANISATION DU FICHIER***********************/
 
reorga(struct liste_ent **ind_nm_ent,struct liste_sta **ind_nm_sta,struct multi_ent_sect **ind_sect_ent,struct multi_ent_sta **ind_ent_sta,struct ple_ent **pile_ent,struct ple_sta **pile_sta)
{
struct entreprise tmp_ent;
struct stagiaire tmp_sta;
int i;
FILE *psta;
FILE *pent;
 
pent=fopen(ENTR,"rb" );
psta=fopen(STA,"rb" );
i=0;
while (fread(&tmp_ent,sizeof(struct entreprise),1,pent))
 {
 if (tmp_ent.cle!=-1)
    {
  insert_ent(ind_nm_ent,tmp_ent.cle,tmp_ent.nom,i);
  insert_multi_ent_sect(ind_sect_ent,&tmp_ent,i);
  }
 else
  {
  push_ent(pile_ent,i);
  }
 i++;
 }
i=0;
while (fread(&tmp_sta,sizeof(struct stagiaire),1,psta))
 {
 if (tmp_sta.cle!=-1)
    {
  insert_sta(ind_nm_sta,tmp_sta.cle,tmp_sta.nom,i);
  insert_multi_ent_sta(ind_ent_sta,&tmp_sta,i);
  }
 else
  {
  push_sta(pile_sta,i);
  }
 i++;
 }
fclose (pent);
fclose(psta);
}
 
 
/*********************FONCTION DE COMPACTAGE **************************/
 
compact(struct liste_ent **ind_nm_ent,struct liste_sta **ind_nm_sta,struct multi_ent_sect **ind_sect_ent,struct multi_ent_sta **ind_ent_sta,struct ple_ent**pile_ent,struct ple_sta**pile_sta)
{
int i,j;
FILE * f_tmp;
FILE *psta;
FILE *pent;
struct liste_ent *ent;
struct liste_sta *sta;
struct entreprise tmp_ent;
struct stagiaire tmp_sta;
struct temp tmp_temp;
char nom[50];
 
while(*pile_ent!=NULL)
 {
 pop_ent(pile_ent);
 }
while(*pile_sta!=NULL)
 {
 pop_sta(pile_sta);
 }
while(*ind_nm_ent!=NULL)
 {
 free(*ind_nm_ent);
 *ind_nm_ent=(*ind_nm_ent)->suivant;
 }
while(*ind_nm_sta!=NULL)
 {
 free(*ind_nm_sta);
 *ind_nm_sta=(*ind_nm_sta)->suivant;
 }
pent=fopen(ENTR,"rb" );
while (*ind_sect_ent!=NULL)
 {
 ent=(*ind_sect_ent)->prem_ent;
 fseek(pent,sizeof(struct entreprise)*ent->posi,SEEK_SET);
 fread(&tmp_ent,sizeof(struct entreprise),1,pent);
 del_multi_ent_sect(ind_sect_ent,&tmp_ent,ent->posi);
 }
while (*ind_ent_sta!=NULL)
 {
 sta=(*ind_ent_sta)->prem_sta;
 del_ent_sta(ind_ent_sta,(*ind_ent_sta)->cle_ent,sta->posi);
 }
 
i=0;
rewind(pent);
f_tmp=fopen(TMP,"wb" );
while (fread(&tmp_ent,sizeof(struct entreprise),1,pent))
 {
 if (tmp_ent.cle!=-1)
    {
  insert_ent(ind_nm_ent,tmp_ent.cle,tmp_ent.nom,i);
  insert_multi_ent_sect(ind_sect_ent,&tmp_ent,i);
  fwrite(&tmp_ent,sizeof(struct entreprise),1,f_tmp);
  i++;
  }
 }
fclose(pent);
fclose(f_tmp);
remove(ENTR);
rename(TMP,ENTR);
j=0;
f_tmp=fopen(TMP,"wb" );
psta=fopen(STA,"rb" );
while (fread(&tmp_sta,sizeof(struct stagiaire),1,psta))
 {
 if (tmp_sta.cle!=-1)
    {
  insert_sta(ind_nm_sta,tmp_sta.cle,tmp_sta.nom,j);
  insert_multi_ent_sta(ind_ent_sta,&tmp_sta,j);
  fwrite(&tmp_sta,sizeof(struct stagiaire),1,f_tmp);
  j++;
  }
 }
fclose(psta);
fclose(f_tmp);
remove(STA);
rename(TMP,STA);
f_tmp=fopen(TEMP,"r+b" );
fread(&tmp_temp,sizeof(struct temp),1,f_tmp);
tmp_temp.posi_ent=i;
tmp_temp.posi_ent=j;
rewind(f_tmp);
fwrite(&tmp_temp,sizeof(struct temp),1,f_tmp);
fclose(f_tmp);
}


n°437292
kadreg
profil: Utilisateur
Posté le 23-06-2003 à 13:45:27  profilanswer
 

C'est quoi cette horreur ?
 
Tu as eut la moyenne avec cette chose ?


---------------
brisez les rêves des gens, il en restera toujours quelque chose...  -- laissez moi troller sur discu !
n°437293
antp
Super Administrateur
Champion des excuses bidons
Posté le 23-06-2003 à 13:46:47  profilanswer
 

ça nous fait une belle jambe [:mlc]


---------------
mes programmes ·· les voitures dans les films ·· apprenez à écrire
n°437294
brash
voir signature!
Posté le 23-06-2003 à 13:47:10  profilanswer
 

kadreg a écrit :

C'est quoi cette horreur ?
 
Tu as eut la moyenne avec cette chose ?


 
c'est dla bombe bébé

n°437295
urd-sama
waste of space
Posté le 23-06-2003 à 13:48:00  profilanswer
 

brash a écrit :


c'est dla bombe bébé


 :heink:


---------------
.: Clône de Drasche .:. Ebichuleys .:. Avec l'Aloe Vera je fais de beaux cacas [:dawa] .: www.oserselancer.com :.
n°437296
brash
voir signature!
Posté le 23-06-2003 à 13:48:01  profilanswer
 

antp a écrit :

ça nous fait une belle jambe [:mlc]


 
merci de ta reconnaissance. je tient à etre accepté dans votre club très fermé des programmateurs à la jambe de bois.

n°437297
brash
voir signature!
Posté le 23-06-2003 à 13:48:25  profilanswer
 


 
probleme? viens me retrouver a la kermesse de st vith si oui! :fou:

n°437298
urd-sama
waste of space
Posté le 23-06-2003 à 13:49:29  profilanswer
 

brash a écrit :


probleme? viens me retrouver a la kermesse de st vith si oui! :fou:


 :heink:  :sweat:


---------------
.: Clône de Drasche .:. Ebichuleys .:. Avec l'Aloe Vera je fais de beaux cacas [:dawa] .: www.oserselancer.com :.
n°437299
chrisbk
-
Posté le 23-06-2003 à 13:50:04  profilanswer
 

Citation :

fflush(stdin);


 
mais que fais taz ? [:ddr555]

mood
Publicité
Posté le 23-06-2003 à 13:50:04  profilanswer
 

n°437300
kadreg
profil: Utilisateur
Posté le 23-06-2003 à 13:50:07  profilanswer
 

brash a écrit :


 
c'est dla bombe bébé


 
Bah oui.
 
Pas de commentaires, des define à la con (c'est quoi la différence entre TMP et TEMP ? ), des tailles de chaines fixes.
 
Après 10 lignes, j'ai craqué.


---------------
brisez les rêves des gens, il en restera toujours quelque chose...  -- laissez moi troller sur discu !
n°437301
brash
voir signature!
Posté le 23-06-2003 à 13:51:28  profilanswer
 

kadreg a écrit :


 
Bah oui.
 
Pas de commentaires, des define à la con (c'est quoi la différence entre TMP et TEMP ? ), des tailles de chaines fixes.
 
Après 10 lignes, j'ai craqué.


 
l'important c ke le programmateur omprenne, pas les noobs qui trainent autour  :kaola:  
 
Je suis le programmateur, je suis DIEU, le tout puissant!

n°437302
brash
voir signature!
Posté le 23-06-2003 à 13:51:43  profilanswer
 

chrisbk a écrit :

Citation :

fflush(stdin);


 
mais que fais taz ? [:ddr555]


 
il baze?

n°437303
brash
voir signature!
Posté le 23-06-2003 à 13:52:21  profilanswer
 


 
allez viende seulement si t un vrai programmateur a la jambe de bois! :fou:

n°437304
gm_superst​ar
Appelez-moi Super
Posté le 23-06-2003 à 13:53:56  profilanswer
 

Comme quoi le C est nocif à la santé mentale :/
 
Edit: [:nraynaud]


Message édité par gm_superstar le 23-06-2003 à 13:55:35

---------------
Incongru : une FAQ abandonnée sur les Standards du Web - FAQ périmée de blabla@Prog
n°437305
LetoII
Le dormeur doit se réveiller
Posté le 23-06-2003 à 13:54:02  profilanswer
 

C quoi ste merde t'aurais pu au moin utiliser les balises de code que ça ressemble à qqc.
 
Edit: c un troll spas possible.


Message édité par LetoII le 23-06-2003 à 13:59:31

---------------
Le Tyran
n°437306
Loom the G​loom
Even coders get the blues...
Posté le 23-06-2003 à 13:54:39  profilanswer
 

[:loom the gloom]


---------------
Music|Market|Feed|Loom|DVD
n°437307
urd-sama
waste of space
Posté le 23-06-2003 à 13:57:30  profilanswer
 

brash a écrit :


allez viende seulement si t un vrai programmateur a la jambe de bois! :fou:


je suis dispensée alors  [:boidleau]


---------------
.: Clône de Drasche .:. Ebichuleys .:. Avec l'Aloe Vera je fais de beaux cacas [:dawa] .: www.oserselancer.com :.
n°437308
drasche
Posté le 23-06-2003 à 13:58:00  profilanswer
 

les balises CPP c'est fait pour quoi? :heink:
 
[:docbrown]
 
et gueule pas trop vite avec ta fête de Saint-Vith, ya quelques belges de bonne carrure ici :o
 
edit: en fait c'est super moche ton truc, je t'aurais collé un zéro pointé pour absence de commentaires :fou:


Message édité par drasche le 23-06-2003 à 13:58:46

---------------
Whichever format the fan may want to listen is fine with us – vinyl, wax cylinders, shellac, 8-track, iPod, cloud storage, cranial implants – just as long as it’s loud and rockin' (Billy Gibbons, ZZ Top)
n°437309
LetoII
Le dormeur doit se réveiller
Posté le 23-06-2003 à 13:58:40  profilanswer
 

brash a écrit :


 
l'important c ke le programmateur omprenne, pas les noobs qui trainent autour  :kaola:  
 
Je suis le programmateur, je suis DIEU, le tout puissant!


 
Tu veux dire les trucs sur les machines à laver?


---------------
Le Tyran
n°437310
Joel F
Real men use unique_ptr
Posté le 23-06-2003 à 14:00:43  profilanswer
 

Leto arrete de repomper mes blagues :D  :pt1cable:  
sinon perso 3/10 arf  :pt1cable:  [:tapai]

n°437311
polo021
Posté le 23-06-2003 à 14:10:16  profilanswer
 

nan mais franchement là meme moi je pense pouvoir faire mieux alors c'est pas rien.[:toto le hros]
 
C'est null :o

n°437312
kadreg
profil: Utilisateur
Posté le 23-06-2003 à 14:11:04  profilanswer
 

polo021 a écrit :


C'est null :o


 
ta mère en short :o


---------------
brisez les rêves des gens, il en restera toujours quelque chose...  -- laissez moi troller sur discu !
n°437313
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 23-06-2003 à 14:13:39  profilanswer
 

c'est bruno [:yaisse2]


---------------
J'ai un string dans l'array (Paris Hilton)
n°437314
chrisbk
-
Posté le 23-06-2003 à 14:13:50  profilanswer
 

kadreg a écrit :


 
ta mère en short :o


 
Ah oui, mais la ca nous fait poutre sur caribou, tu recules de deux cases et poses deux cartes chances sur pioche [:aloy]

n°437315
gm_superst​ar
Appelez-moi Super
Posté le 23-06-2003 à 14:16:51  profilanswer
 
n°437316
antp
Super Administrateur
Champion des excuses bidons
Posté le 23-06-2003 à 14:17:59  profilanswer
 

:non: en std::string


---------------
mes programmes ·· les voitures dans les films ·· apprenez à écrire
n°437317
Loom the G​loom
Even coders get the blues...
Posté le 23-06-2003 à 14:19:00  profilanswer
 

brash, brash, ce pseudo me dit qqchose [:meganne]


---------------
Music|Market|Feed|Loom|DVD
n°437318
kadreg
profil: Utilisateur
Posté le 23-06-2003 à 14:19:00  profilanswer
 

antp a écrit :

:non: en std::string


 
en char*


---------------
brisez les rêves des gens, il en restera toujours quelque chose...  -- laissez moi troller sur discu !
n°437319
polo021
Posté le 23-06-2003 à 14:19:16  profilanswer
 

gm_superstar a écrit :


Et la tienne en string.h :o


on s'en fout de CString a sa maman  :o

n°437320
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 23-06-2003 à 14:23:21  profilanswer
 

Loom the gloom a écrit :

brash, brash, ce pseudo me dit qqchose [:meganne]

ben je viens de dire que c'était bruno [:sinclaire]


---------------
J'ai un string dans l'array (Paris Hilton)
n°437321
chrisbk
-
Posté le 23-06-2003 à 14:25:12  profilanswer
 

Code :
  1. # include <stdio.h>
  2. # include <stdlib.h>
  3. # include <alloc.h>
  4. # include <string.h>
  5. # define ENTR "c:\\etudiant\\entre.dat"
  6. # define STA "c:\\etudiant\\stag.dat"
  7. # define TEMP "c:\\etudiant\\temp.dat"
  8. # define TMP "c:\\etudiant\\tmp.dat"
  9. # define NB_SYNO 10
  10. struct entreprise {
  11.     int cle;
  12.     char nom[25+1];
  13.     char addresse[25+1];
  14.     int codepost;
  15.     char ville[25+1];
  16.     char tel[20+1];
  17.     char secteur[20+1];
  18.                 };
  19. struct stagiaire
  20.     {
  21.     int cle;
  22.     char nom[25+1];
  23.     int cle_etr;
  24.     char prenom[25+1];
  25.     char addresse[25+1];
  26.     int codepost;
  27.     char ville[25+1];
  28.     char tel[20+1];
  29.     char tel_ent[20+1];
  30.                 };
  31. struct liste_ent
  32.     {
  33.     int cle;
  34.     char nom[25+1];
  35.     int posi;
  36.     struct liste_ent *suivant;
  37.     };
  38. struct liste_sta
  39.     {
  40.     int cle;
  41.     char nom[25+1];
  42.     int posi;
  43.     struct liste_sta *suivant;
  44.     };
  45. struct ple_ent
  46.    {
  47.    int posi;
  48.    struct ple_ent *suivant;
  49.    };
  50. struct ple_sta
  51.    {
  52.    int posi;
  53.    struct ple_sta *suivant;
  54.    };
  55. struct temp
  56.    {
  57.    int cle_ent;
  58.    int cle_sta;
  59.    int posi_ent;
  60.    int posi_sta;
  61.    };
  62. struct multi_ent_sect
  63.     {
  64.     char secteur[25+1];
  65.     struct liste_ent *prem_ent;
  66.     struct multi_ent_sect *suivant;
  67.     };
  68. struct multi_ent_sta
  69.     {
  70.     int cle_ent;
  71.     struct liste_sta *prem_sta;
  72.              struct multi_ent_sta *suivant;
  73.     };
  74. crea_temp();
  75. add_ent(struct liste_ent**,struct multi_ent_sect**,struct ple_ent**);
  76. add_sta(struct liste_sta** ,struct multi_ent_sta** ,struct liste_ent**,struct ple_sta**);
  77. modif_sup_ent(struct liste_ent**,struct multi_ent_sect**,struct ple_ent**,struct multi_ent_sta**);
  78. modif_sup_sta(struct liste_sta**,struct multi_ent_sta**,struct liste_ent**ind_nm_ent,struct ple_sta**);
  79. modipent(struct liste_ent**,struct multi_ent_sect**,int);
  80. modipsta(struct liste_sta**,struct multi_ent_sta**,struct liste_ent**ind_nm_ent,int);
  81. afpent(struct entreprise*);
  82. afpsta(struct stagiaire*);
  83. aff_sec_ent();
  84. aff_sec_sta();
  85. afpent_ind(struct liste_ent*);
  86. afpsta_ind(struct liste_sta*);
  87. aff_sect_ent(struct multi_ent_sect*);
  88. aff_sect_ent_spec(struct multi_ent_sect*);
  89. afpent_sta(struct multi_ent_sta*);
  90. afpent_sta_spec(struct multi_ent_sta*);
  91. afpsta_sect(struct multi_ent_sect*,struct multi_ent_sta*);
  92. afpsta_sect(struct multi_ent_sect*,struct multi_ent_sta*);
  93. insert_ent(struct liste_ent**,int,char *,int);
  94. insert_sta (struct liste_sta**,int,char *,int);
  95. insert_multi_ent_sect(struct multi_ent_sect**,struct entreprise*,int);
  96. insert_multi_ent_sta(struct multi_ent_sta**,struct stagiaire*,int);
  97. new_ent (char * ,struct liste_ent **,int,struct liste_ent*,int );
  98. new_sta (char * ,struct liste_sta **,int,struct liste_sta*,int );
  99. seek_ent(struct liste_ent * ,char *,int []);
  100. seek_sta(struct liste_sta *,char *,int []);
  101. int seek_ent_sta(struct multi_ent_sta*,int);
  102. del_ent(struct liste_ent**,int);
  103. del_sta(struct liste_sta**,int);
  104. del_multi_ent_sect(struct multi_ent_sect**,struct entreprise*,int);
  105. del_ent_sta(struct multi_ent_sta**,int,int);
  106. push_ent(struct ple_ent**,int);
  107. push_sta(struct ple_sta**,int);
  108. pop_ent(struct ple_ent**);
  109. pop_sta(struct ple_sta**);
  110. reorga(struct liste_ent**,struct liste_sta**,struct multi_ent_sect**,struct multi_ent_sta**,struct ple_ent**,struct ple_sta**);
  111. compact(struct liste_ent**,struct liste_sta**,struct multi_ent_sect**,struct multi_ent_sta**,struct ple_ent**,struct ple_sta**);
  112. main ()
  113. {
  114. struct ple_ent *pile_ent;
  115. struct ple_sta *pile_sta;
  116. struct liste_ent *ind_nm_ent;
  117. struct liste_sta  *ind_nm_sta;
  118. struct multi_ent_sect *ind_sect_ent;
  119. struct multi_ent_sta *ind_ent_sta;
  120. int rep1,rep2,rep3;
  121. crea_temp();
  122. ind_nm_ent=NULL;
  123. ind_nm_sta=NULL;
  124. ind_sect_ent=NULL;
  125. ind_ent_sta=NULL;
  126. pile_ent=NULL;
  127. pile_sta=NULL;
  128. reorga(&ind_nm_ent,&ind_nm_sta,&ind_sect_ent,&ind_ent_sta,&pile_ent,&pile_sta);
  129. do{
  130.   do{
  131. clrscr();
  132. printf("MENU PRINCIPAL\n" ) ;
  133. printf("1)Menu Ajout de fiches\n" );
  134. printf("2)Modification ou supression de fiches\n" );
  135. printf("3)Affichage de fiches\n" );
  136. printf("4)Fonction de compactage\n" );
  137. printf("5)Quitter" );
  138. fflush(stdin);
  139. scanf("%d",&rep1);
  140. }
  141.   while(rep1<1 || rep1>5);
  142.   switch (rep1)
  143. {
  144. case (1):
  145.   {
  146.   do {
  147.    do {
  148.     rep2=0;
  149.     clrscr();
  150.     printf("1)Ajout d'une entreprise\n" );
  151.     printf("2)Ajout d'un  stagiaire\n" );
  152.     printf("3)quitter" );
  153.     fflush(stdin);
  154.     scanf("%d",&rep2);
  155.     }
  156.    while(rep2<1 || rep2>3);
  157.    switch (rep2)
  158.     {
  159.     case(1):
  160.      {
  161.      clrscr();
  162.      add_ent(&ind_nm_ent,&ind_sect_ent,&pile_ent);
  163.      break;
  164.      }
  165.     case(2):
  166.      {
  167.                     clrscr();
  168.      add_sta(&ind_nm_sta,&ind_ent_sta,&ind_nm_ent,&pile_sta);
  169.      break;
  170.      }
  171.     }
  172.      }
  173.   while (rep2!=3);
  174.   break;
  175.   }
  176. case(2):
  177.   {
  178.   do {
  179.      do {
  180.      rep2=0;
  181.      clrscr();
  182.      printf("1)Recherche d'une entreprise\n" );
  183.      printf("2)Recherche d'un stagiaire\n" );
  184.      printf("3)Quitter" );
  185.      fflush(stdin);
  186.      scanf("%d",&rep2);
  187.      }
  188.      while(rep2<1 || rep2>3);
  189.      switch (rep2)
  190.    {
  191.    case (1):
  192.     {
  193.                 clrscr ();
  194.     modif_sup_ent(&ind_nm_ent,&ind_sect_ent,&pile_ent,&ind_ent_sta);
  195.     break;
  196.     }
  197.    case (2):
  198.     {
  199.     clrscr ();
  200.     modif_sup_sta(&ind_nm_sta,&ind_ent_sta,&ind_nm_ent,&pile_sta);
  201.     break;
  202.     }
  203.    }
  204.     }
  205.   while(rep2!=3);
  206.   break;
  207.   }
  208. case (3):
  209.   {
  210.   do {
  211.    do {
  212.     rep2=0;
  213.     clrscr();
  214.     printf("1)Affichage des entreprises\n" );
  215.     printf("2)Affichage des stagiaires\n" );
  216.     printf("3)Quitter" );
  217.     fflush(stdin);
  218.     scanf("%d",&rep2);
  219.     }
  220.    while(rep2<1 || rep2>3);
  221.    switch (rep2)
  222.      {
  223.      case(1):
  224.       {
  225.       do {
  226.        do {
  227.         rep3=0;
  228.         clrscr();
  229.         printf("1)Affichage sequentiel des entreprises\n" );
  230.         printf("2)Affichage des entreprises triees par nom\n" );
  231.         printf("3)Affichage des entreprises par secteur\n" );
  232.         printf("4)Affichage des entreprises d'un secteur specifique\n" );
  233.         printf("5)Quitter" );
  234.         fflush(stdin);
  235.         scanf("%d",&rep3);
  236.         }
  237.        while(rep3<1 || rep3>5);
  238.        switch (rep3)
  239.         {
  240.         case(1):
  241.           {
  242.           aff_sec_ent();
  243.           break;
  244.           }
  245.         case(2):
  246.          {
  247.          afpent_ind(ind_nm_ent);
  248.          break;
  249.          }
  250.         case(3):
  251.          {
  252.          aff_sect_ent(ind_sect_ent);
  253.          break;
  254.          }
  255.         case(4):
  256.          {
  257.          aff_sect_ent_spec(ind_sect_ent);
  258.          break;
  259.          }
  260.         }
  261.          }
  262.       while (rep3!=5);
  263.       break;
  264.       }
  265.      case(2):
  266.       {
  267.                         do {
  268.        do {
  269.         rep3=0;
  270.         clrscr();
  271.         printf("1)Affichage sequentiel des stagiaires\n" );
  272.         printf("2)Affichage des stagiaires tries par nom\n" );
  273.         printf("3)Affichage des stagiaires par entreprise\n" );
  274.         printf("4)Affichage des stagiaires d'une entreprise specifique\n" );
  275.         printf("5)Affichage des stagiaires par secteur\n" );
  276.         printf("6)Affichage des stagiaires d'un secteur specique\n" );
  277.         printf("7)quitter" );
  278.         fflush(stdin);
  279.         scanf("%d",&rep3);
  280.         }
  281.        while(rep3<1 || rep3>7);
  282.        switch (rep3)
  283.         {
  284.         case(1):
  285.          {
  286.          aff_sec_sta();
  287.          break;
  288.           }
  289.         case(2):
  290.          {
  291.          afpsta_ind(ind_nm_sta);
  292.          break;
  293.          }
  294.         case(3):
  295.          {
  296.          afpent_sta(ind_ent_sta);
  297.          break;
  298.          }
  299.                                 case(4):
  300.          {
  301.          afpent_sta_spec(ind_ent_sta);
  302.          break;
  303.          }
  304.         case(5):
  305.          {
  306.          afpsta_sect(ind_sect_ent,ind_ent_sta);
  307.          break;
  308.          }
  309.         case(6):
  310.          {
  311.          afpsta_sect_spec(ind_sect_ent,ind_ent_sta);
  312.          break;
  313.          }
  314.         }
  315.        }
  316.       while (rep3!=7);
  317.       break;
  318.       }
  319.      }
  320.   }
  321.   while(rep2!=3);
  322. break;
  323. }
  324.   case(4):
  325.   {
  326.   compact(&ind_nm_ent,&ind_nm_sta,&ind_sect_ent,&ind_ent_sta,&pile_ent,&pile_sta);
  327.   break;
  328.   }
  329.   }
  330. }
  331. while (rep1!=5);
  332. }
  333. /****************FONCTION DE CREATION DU FICHIER TEMP***********************/
  334. crea_temp()
  335. {
  336. FILE *ptemp;
  337. int i;
  338. struct temp tmp;
  339. ptemp=fopen(TEMP,"r+b" );
  340. if(!ptemp)
  341. {
  342. ptemp=fopen(TEMP,"wb" );
  343. tmp.cle_ent=0;
  344. tmp.cle_sta=0;
  345. tmp.posi_ent=0;
  346. tmp.posi_sta=0;
  347. fwrite(&tmp,sizeof(struct temp),1,ptemp);
  348. }
  349. fclose(ptemp);
  350. }
  351. /*******************FONCTION D'AJOUT D'UN RECORD ENTTREPRISE***************/
  352. add_ent(struct liste_ent **ind_nm_ent,struct multi_ent_sect **ind_sect_ent,struct ple_ent **pile_ent)
  353. {
  354. char essai[128],rep;
  355. FILE *ptemp,*pent;
  356. struct entreprise tmp;
  357. struct temp tmp_temp;
  358. do {
  359.                 clrscr();
  360. printf("\nEntrer le nom de l'entreprise:   " );
  361. fflush(stdin);
  362. gets(essai);
  363. if (strlen(essai)>25) printf("\nVous devez entrer un nom de maximum 25 caracteres" );
  364. }
  365. while (strlen(essai)>25);
  366. strcpy(tmp.nom,essai);
  367. do {
  368. printf("\nEntrer l'addresse de l'entreprise:   " );
  369. fflush(stdin);
  370. gets(essai);
  371. if (strlen(essai)>25) printf("\nVous devez entrer une addresse de maximum 25 caracteres" );
  372. }
  373. while (strlen(essai)>25);
  374. strcpy(tmp.addresse,essai);
  375. do {
  376. tmp.codepost=0;
  377. printf("\nEntrer le code postal de l'entreprise, celui-ci doit etre compris entre 1000 et 9999 inclus :   " );
  378. fflush(stdin);
  379. scanf("%d",&tmp.codepost);
  380. }
  381. while(tmp.codepost <1000 ||tmp.codepost>9999);
  382. do {
  383. printf("\nEntrer la ville de l'entreprise:   " );
  384. fflush(stdin);
  385. gets(essai);
  386. if (strlen(essai)>25) printf("\nVous devez entrer une ville de maximum 25 caracteres" );
  387. }
  388. while (strlen(essai)>25);
  389. strcpy(tmp.ville,essai);
  390. do {
  391. printf("\nEntrer le numéro de  téléphone de l'entreprise:   " );
  392. fflush(stdin);
  393. gets(essai);
  394. if (strlen(essai)>20) printf("\nVous devez entrer un numero de telephone de maximum 20 caracteres" );
  395. }
  396. while (strlen(essai)>20);
  397. strcpy(tmp.tel,essai);
  398. do {
  399. printf("\nEntrer le secteur d'activite de l'entreprise:   " );
  400. fflush(stdin);
  401. gets(essai);
  402. if (strlen(essai)>25) printf("\nVous devez entrer un intitule de secteur de maximum 25 caracteres" );
  403. }
  404. while (strlen(essai)>25);
  405. strcpy(tmp.secteur,essai);
  406. do
  407.   {
  408.   printf("Etes vous sur de vouloir ajouter cette fiche(o/n)?" );
  409.   fflush(stdin);
  410.   rep=getchar();
  411.   rep=tolower(rep);
  412.   }
  413. while(rep!='o' && rep!='n');
  414. if (rep=='o')
  415.    {
  416.    ptemp=fopen(TEMP,"r+b" );
  417.    pent=fopen(ENTR,"r+b" );
  418.    if (!pent) pent=fopen(ENTR,"wb" );
  419.    fread(&tmp_temp,sizeof(struct temp),1,ptemp);
  420.    tmp.cle=tmp_temp.cle_ent;
  421.    if(*pile_ent==NULL)
  422.    {
  423.    fseek(pent,sizeof(struct entreprise)*tmp_temp.posi_ent,SEEK_SET);
  424.    insert_ent(ind_nm_ent,tmp.cle,tmp.nom,tmp_temp.posi_ent);
  425.    insert_multi_ent_sect(ind_sect_ent,&tmp,tmp_temp.posi_ent);
  426.       tmp_temp.posi_ent++;
  427.    }
  428.    else
  429.   {
  430.   fseek(pent,sizeof(struct entreprise)* (*pile_ent)->posi,SEEK_SET);
  431.   insert_ent(ind_nm_ent,tmp_temp.cle_ent,tmp.nom,(*pile_ent)->posi);
  432.   insert_multi_ent_sect(ind_sect_ent,&tmp,(*pile_ent)->posi);
  433.   pop_ent (pile_ent);
  434.   }
  435.    fwrite(&tmp,sizeof(struct entreprise),1,pent);
  436.    fclose(pent);
  437.    tmp_temp.cle_ent++;
  438.    rewind(ptemp);
  439.    fwrite(&tmp_temp,sizeof(struct temp),1,ptemp);
  440.    fclose(ptemp);
  441.    }
  442. }
  443. /***************************FONCTION D'AJOUT D'UN RECORD STAGIAIRE*******/
  444. add_sta (struct liste_sta **ind_nm_sta,struct multi_ent_sta **ind_ent_sta,struct liste_ent **ind_nm_ent,struct ple_sta **pile_sta)
  445. {
  446. char essai[128],nomch[25+1],rep,rep2;
  447. int vec[10],i;
  448. FILE *ptemp,*psta,*pent;
  449. struct stagiaire tmp;
  450. struct temp tmp_temp;
  451. struct entreprise tmp_ent;
  452. if (*ind_nm_ent==NULL) {printf("Aucune entreprise existante, vous devez d'abord en entrer une!" );fflush(stdin);getch();}
  453. else {
  454. pent=fopen(ENTR,"r+b" );
  455. do {
  456. printf("\nEntrer le nom du stagiaire:   " );
  457. fflush(stdin);
  458. gets(essai);
  459. if (strlen(essai)>25) printf("\nVous devez entrer un nom de stagiaire de maximum 25 caracteres" );
  460. }
  461. while (strlen(essai)>25);
  462. strcpy(tmp.nom,essai);
  463. do {
  464. printf("\nEntrer le prenom du stagiaire:   " );
  465. fflush(stdin);
  466. gets(essai);
  467. if (strlen(essai)>25) printf("\nVous devez entrer un prenom de stagiaire de maximum 25 caractere" );
  468. }
  469. while (strlen(essai)>25);
  470. strcpy(tmp.prenom,essai);
  471. do {
  472. printf("\nEntrer l'addresse du stagiaire:   " );
  473. fflush(stdin);
  474. gets(essai);
  475. if (strlen(essai)>25) printf("\nVous devez entrer une addresse de stagiaire de maximum 25 caractere" );
  476. }
  477. while (strlen(essai)>25);
  478. strcpy(tmp.addresse,essai);
  479. do {
  480.    tmp.codepost=0;
  481.    printf("\nEntrer le code postal du stagiaire,celui-ci doit etre entre 1000 et 9999 inclus:   " );
  482.    fflush(stdin);
  483.    scanf("%d",&tmp.codepost);
  484.    }
  485. while(tmp.codepost <1000 ||tmp.codepost>9999);
  486. do {
  487. printf("\nEntrer la ville du stagiaire:   " );
  488. fflush(stdin);
  489. gets(essai);
  490. if (strlen(essai)>25) printf("\nVous devez entrer une ville de maximum 25 caractere" );
  491. }
  492. while (strlen(essai)>25);
  493. strcpy(tmp.ville,essai);
  494. do {
  495. printf("\nEntrer le numero de telephone prive du stagiaire:   " );
  496. fflush(stdin);
  497. gets(essai);
  498. if (strlen(essai)>20) printf("\nVous devez entrer un numero de telephone de maximum 20 caractere" );
  499. }
  500. while (strlen(essai)>20);
  501. strcpy(tmp.tel,essai);
  502. do {
  503. printf("\nEntrer le numero de telephone de l'entreprise du stagiaire:   " );
  504. fflush(stdin);
  505. gets(essai);
  506. if (strlen(essai)>20) printf("\nVous devez entrer un numero de telephone de maximum 20 caractere" );
  507. }
  508. while (strlen(essai)>20);
  509. strcpy(tmp.tel_ent,essai);
  510. do
  511.    {
  512. printf ("\nEntrez le nom de l'entreprise cherchee: " );
  513. fflush (stdin);
  514. gets (nomch);
  515. seek_ent (*ind_nm_ent,nomch,vec);
  516. rep='x';
  517. i=0;
  518. if (vec[i]!=-1)
  519.     {
  520.     while (vec[i]!=-1 && rep!='O' && rep!='A')
  521.     {
  522.     rewind (pent);
  523.     fseek (pent,vec[i]*sizeof(struct entreprise),SEEK_SET);
  524.     fread(&tmp_ent,sizeof(struct entreprise),1,pent);
  525.     clrscr();
  526.     afpent(&tmp_ent);
  527.     do {
  528.     if(vec[i+1]!=-1) printf ("\nAppuier sur O pour mettre cette fiche N pour voir la fiche suivante  A pour Annuler: " );
  529.     else printf ("\nAppuier sur O pour mettre cette fiche A pour Annuler: " );
  530.     fflush (stdin);
  531.     rep=getchar ();
  532.     rep=toupper (rep);
  533.     }
  534.     while (rep!='A' &&  rep!='O' && rep!='N');
  535.     if (rep=='O')
  536.     {
  537.     tmp.cle_etr=tmp_ent.cle;
  538.     }
  539.     i++;
  540.     }
  541.     }
  542.   else
  543.    {
  544.    printf ("\nCe nom n'existe pas\n" );
  545.    do {
  546.     printf ("\nO pour rechercher une autre entreprise A pour Annuler: " );
  547.     fflush (stdin);
  548.     rep2=getchar ();
  549.     rep2=toupper (rep2);
  550.     }
  551.    while (rep2!='A' &&  rep2!='O');
  552.    }
  553. }
  554. while (rep!='O' && rep2!='A');
  555. if (rep=='O')
  556.    {
  557. do
  558.    {
  559.    printf("Voulez etes sur de vouloir ajouter cette fiche(o/n)?" );
  560.    fflush(stdin);
  561.    rep=getchar();
  562.    rep=tolower(rep);
  563.    }
  564. while(rep!='o' && rep!='n');
  565.    }
  566. }
  567. if(rep=='o')
  568.   {
  569.   ptemp=fopen(TEMP,"r+b" );
  570.   psta=fopen(STA,"r+b" );
  571.    if (!psta) psta=fopen(STA,"wb" );
  572.   fread(&tmp_temp,sizeof(struct temp),1,ptemp);
  573.   tmp.cle=tmp_temp.cle_sta;
  574.   if(*pile_sta==NULL)
  575. {
  576. fseek(psta,sizeof(struct stagiaire)*tmp_temp.posi_sta,SEEK_SET);
  577. insert_sta(ind_nm_sta,tmp.cle,tmp.nom,tmp_temp.posi_sta);
  578. insert_multi_ent_sta(ind_ent_sta,&tmp,tmp_temp.posi_sta);
  579. tmp_temp.posi_sta++;
  580. }
  581.   else
  582. {
  583. fseek(psta,sizeof(struct stagiaire)*(*pile_sta)->posi,SEEK_SET);
  584. insert_sta(ind_nm_sta,tmp.cle,tmp.nom,(*pile_sta)->posi);
  585. insert_multi_ent_sta(ind_ent_sta,&tmp,(*pile_sta)->posi);
  586. pop_sta (pile_sta);
  587. }
  588.   fwrite(&tmp,sizeof(struct stagiaire),1,psta);
  589.   tmp_temp.cle_sta++;
  590.   rewind(ptemp);
  591.   fwrite(&tmp_temp,sizeof(struct temp),1,ptemp);
  592.   fclose(ptemp);
  593.   fclose(psta);
  594.   }
  595. fclose(pent);
  596. }
  597. /******FONCTION DE MODIFICATION OU DE SUPRESSION D'UNE ENTREPRISE************/
  598. modif_sup_ent(struct liste_ent **ind_nm_ent,struct multi_ent_sect **ind_sect_ent,struct ple_ent **pile_ent,struct multi_ent_sta **ind_ent_sta)
  599. {
  600. char essai[128],nomch[25+1],rep,rep2;
  601. int vec[10],i,valid;
  602. FILE *pent;
  603. struct stagiaire tmp;
  604. struct entreprise tmp_ent;
  605. pent=fopen(ENTR,"r+b" );
  606. printf ("Entrez le nom de l'entreprise  recherchee:   " );
  607. fflush (stdin);
  608. gets (nomch);
  609. seek_ent (*ind_nm_ent,nomch,vec);
  610. rep='x';
  611. i=0;
  612. if (vec[i]!=-1)
  613.    {
  614. while (vec[i]!=-1  && rep!='A')
  615.   {
  616.   fseek (pent,vec[i]*sizeof(struct entreprise),SEEK_SET);
  617.   fread(&tmp_ent,sizeof(struct entreprise),1,pent);
  618.   clrscr();
  619.   afpent(&tmp_ent);
  620.   do {
  621.    if(vec[i+1]!=-1) printf ("\n M pour Modifier \n S pour Suprimer \n A pour Annuler \n N pour Next: " );
  622.    else printf ("\n M pour Modifier \n S pour Suprimer \n A pour Annuler: " );
  623.    fflush (stdin);
  624.    rep=getchar ();
  625.    rep=toupper (rep);
  626.    }
  627.   while (rep!='A' && rep!='S' && rep!='M' && rep!='N');
  628.   if (rep=='M')
  629.    {
  630.    modipent(ind_nm_ent,ind_sect_ent,vec[i]);
  631.    }
  632.    else
  633.     {
  634.     if (rep=='S')
  635.      {
  636.      valid=seek_ent_sta(*ind_ent_sta,tmp_ent.cle);
  637.      if (valid==0)
  638.       {
  639.       del_ent (ind_nm_ent,vec[i]);
  640.       del_multi_ent_sect(ind_sect_ent,&tmp_ent,vec[i]);
  641.       tmp_ent.cle=-1;
  642.       fseek (pent,vec[i]*sizeof(struct entreprise),SEEK_SET);
  643.       fwrite(&tmp_ent,sizeof(struct entreprise),1,pent);
  644.       push_ent (pile_ent,vec[i]);
  645.       }
  646.      else {printf("Vous devez supprimer les stagiaires de cette entreprise encore présent" );}
  647.      }
  648.      }
  649.     i++;
  650.   }
  651. }
  652. else { printf ("\nEntreprise non trouvee" );fflush (stdin); getch ();}
  653. fclose(pent);
  654. }
  655. /******FONCTION DE MODIFICATION OU DE SUPRESSION D'UN STAGIAIRE**************/
  656. modif_sup_sta(struct liste_sta **ind_nm_sta,struct multi_ent_sta **ind_ent_sta,struct liste_ent **ind_nm_ent,struct ple_sta **pile_sta)
  657. {
  658. char essai[128],nomch[25+1],rep,rep2;
  659. int vec[10],i;
  660. FILE *psta;
  661. struct stagiaire tmp_sta;
  662. psta=fopen(STA,"r+b" );
  663. printf ("Entrez le nom du stagiaire recherche:   " );
  664. fflush (stdin);
  665. gets (nomch);
  666. rep='x';
  667. i=0;
  668. seek_sta(*ind_nm_sta,nomch,vec);
  669. if (vec[i]!=-1)
  670.    {
  671. while (vec[i]!=-1  && rep!='A')
  672.   {
  673.   fseek (psta,vec[i]*sizeof(struct stagiaire),SEEK_SET);
  674.   fread(&tmp_sta,sizeof(struct stagiaire),1,psta);
  675.   clrscr();
  676.   afpsta(&tmp_sta);
  677.   do {
  678.    if(vec[i+1]!=-1) printf ("\n  M pour Modifier\n S pour Suprimer \n A pour Annuler \n N pour Next: " );
  679.    else printf ("\n  M pour Modifier \n S pour Suprimer \n A pour Annuler: " );
  680.    fflush (stdin);
  681.    rep=getchar ();
  682.    rep=toupper (rep);
  683.    }
  684.   while (rep!='A' && rep!='S' && rep!='M' && rep!='N');
  685.   if (rep=='M')
  686.    {
  687.    modipsta(ind_nm_sta,ind_ent_sta,ind_nm_ent,vec[i]);
  688.    }
  689.   else { if (rep=='S')
  690.     {
  691.     del_sta (ind_nm_sta,vec[i]);
  692.     del_ent_sta(ind_ent_sta,tmp_sta.cle_etr,vec[i]);
  693.     tmp_sta.cle=-1;
  694.     fseek (psta,vec[i]*sizeof(struct stagiaire),SEEK_SET);
  695.     fwrite(&tmp_sta,sizeof(struct stagiaire),1,psta);
  696.     push_sta (pile_sta,vec[i]);
  697.     }
  698.      }
  699.    i++;
  700.    }
  701.    }
  702.   else { printf ("\nCe nom de stagiaire n'existe  pas!" );fflush (stdin); getch ();}
  703. fclose(psta);
  704. }
  705. /*************FONCTION DE MODIFICATION D'UN RECORD ENTREPRISE*************/
  706. modipent(struct liste_ent **ind_nm_ent,struct multi_ent_sect **ind_sect_ent,int posi)
  707. {
  708. char essai[128],rep;
  709. struct entreprise tmp,old;
  710. FILE *pent;
  711. pent=fopen(ENTR,"r+b" );
  712. fseek(pent,sizeof(struct entreprise)*posi,SEEK_SET);
  713. fread(&tmp,sizeof(struct entreprise),1,pent);
  714. fseek(pent,sizeof(struct entreprise)*posi,SEEK_SET);
  715. fread(&old,sizeof(struct entreprise),1,pent);
  716. do {
  717. printf("\nEntrer le nouveau nom de l'entreprise\n appuyez sur ENTER si vous voulez garder %s comme nom:   ",tmp.nom);
  718. fflush(stdin);
  719. gets(essai);
  720. if (strlen(essai)>25) printf("\nVous devez entrer un nom d'entreprise de maximum 25 caractere" );
  721. }
  722. while (strlen(essai)>25);
  723. if (strlen(essai)!=0) strcpy(tmp.nom,essai);
  724. do {
  725. printf("\nEntrer la nouvelle addresse de l'entreprise\n appuyez sur ENTER si vous voulez garder %s comme addresse:   ",tmp.addresse);
  726. fflush(stdin);
  727. gets(essai);
  728. if (strlen(essai)>25) printf("\nVous devez entrer une addresse d'entreprise de maximum 25 caractere" );
  729. }
  730. while (strlen(essai)>25);
  731. if (strlen(essai)!=0) strcpy(tmp.addresse,essai);
  732. do {
  733. tmp.codepost=0;
  734. printf("\nEntrer le code postal de l'entreprise, celui-ci doit etre compris entre 1000 et 9999 inclus:   " );
  735. fflush(stdin);
  736. scanf("%d",&tmp.codepost);
  737. }
  738. while(tmp.codepost <1000 ||tmp.codepost>9999);
  739. do {
  740. printf("\nEntrer la nouvelle ville de l'entreprise\n appuyez sur ENTER si vous voulez garder %s comme ville:   ",tmp.ville);
  741. fflush(stdin);
  742. gets(essai);
  743. if (strlen(essai)>25) printf("\n\nVous devez entrer une ville de maximum 25 caracteres" );
  744. }
  745. while (strlen(essai)>25);
  746. if (strlen(essai)!=0) strcpy(tmp.ville,essai);
  747. do {
  748. printf("\nEntrer le nouveau numero de telephone de l'entreprise\n appuyez sur ENTER si vous voulez garder %s comme telephone:   ",tmp.tel);
  749. fflush(stdin);
  750. gets(essai);
  751. if (strlen(essai)>20) printf("\nVous devez entrer un numero de telephone de maximum 20 caracteres" );
  752. }
  753. while (strlen(essai)>20);
  754. if (strlen(essai)!=0) strcpy(tmp.tel,essai);
  755. do {
  756. printf("\nEntrer le nouveau  secteur d'activite de l'entreprise\n appuyez sur ENTER si vous voulez garder %s comme secteur d'activite:   ",tmp.secteur);
  757. fflush(stdin);
  758. gets(essai);
  759. if (strlen(essai)>25) printf("\nVous devez entrer un intitule de secteur de maximum 25 caracteres" );
  760. }
  761. while (strlen(essai)>25);
  762. if (strlen(essai)!=0) strcpy(tmp.secteur,essai);
  763. do
  764.   {
  765.   printf("\n Etes vous sur de vouloir modifier cette fiche(o/n)?" );
  766.   fflush(stdin);
  767.   rep=getchar();
  768.   rep=tolower(rep);
  769.   }
  770. while(rep!='o' && rep!='n');
  771. if (rep=='o')
  772.   {
  773.   del_ent (ind_nm_ent,posi);
  774.   del_multi_ent_sect(ind_sect_ent,&old,posi);
  775.   fseek (pent,posi*sizeof(struct entreprise),SEEK_SET);
  776.   fwrite(&tmp,sizeof(struct entreprise),1,pent);
  777.   insert_ent(ind_nm_ent,tmp.cle,tmp.nom,posi);
  778.   insert_multi_ent_sect(ind_sect_ent,&tmp,posi);
  779.   }
  780. fclose(pent);
  781. }
  782. /**************FONCTION DE MODIFICATION D'UN RECORD STAGIAIRE************/
  783. modipsta(struct liste_sta**ind_nm_sta,struct multi_ent_sta **ind_ent_sta,struct liste_ent**ind_nm_ent,int posi)
  784. {
  785. char essai[128],nomch[128],rep,rep2;
  786. int i,vec[NB_SYNO];
  787. struct stagiaire tmp,old;
  788. struct entreprise tmp_ent;
  789. FILE *pent,*psta;
  790. pent=fopen(ENTR,"rb" );
  791. psta=fopen(STA,"r+b" );
  792. fseek(psta,sizeof(struct stagiaire)*posi,SEEK_SET);
  793. fread(&tmp,sizeof(struct stagiaire),1,psta);
  794. fseek(psta,sizeof(struct stagiaire)*posi,SEEK_SET);
  795. fread(&old,sizeof(struct stagiaire),1,psta);
  796. do {
  797. printf("\Entrer le nom du stagiaire \n appuyez sur ENTER si vous voulez garder %s comme nom: ",tmp.nom);
  798. fflush(stdin);
  799. gets(essai);
  800. if (strlen(essai)>25) printf("\nVous devez entrer un nom de stagiaire de maximum 25 caracteres" );
  801. }
  802. while (strlen(essai)>25);
  803. if (strlen(essai)!=0) strcpy(tmp.nom,essai);
  804. do {
  805. printf("\nEntrer le prenom du stagiaire\n appuyez sur ENTER si vous voulez garder %s comme prenom: ",tmp.prenom);
  806. fflush(stdin);
  807. gets(essai);
  808. if (strlen(essai)>25) printf("\nVous devez entrer un prenom de stagiaire de maximum 25 caractere" );
  809. }
  810. while (strlen(essai)>25);
  811. if (strlen(essai)!=0) strcpy(tmp.prenom,essai);
  812. do {
  813. printf("\nEntrer l'addresse du stagiaire\n appuyez sur  ENTER si vous voulez garder %s comme addresse: ",tmp.addresse);
  814. fflush(stdin);
  815. gets(essai);
  816. if (strlen(essai)>25) printf("\nVous devez entrer une addresse de stagiaire de maximum 25 caracteres" );
  817. }
  818. while (strlen(essai)>25);
  819. if (strlen(essai)!=0) strcpy(tmp.addresse,essai);
  820. do {
  821.    tmp.codepost=0;
  822.    printf("\nEntrer le code postal du stagiaire,celui-ci doit etre entre 1000 et 9999 inclus:   " );
  823.    fflush(stdin);
  824.    scanf("%d",&tmp.codepost);
  825.    }
  826. while(tmp.codepost <1000 ||tmp.codepost>9999);
  827. do {
  828. printf("\nEntrer la ville du stagiaire\n appuyez ENTER si vous voulez garder %s comme ville: ",tmp.ville);
  829. fflush(stdin);
  830. gets(essai);
  831. if (strlen(essai)>25) printf("\nVous devez entrer une ville de maximum 25 caractere" );
  832. }
  833. while (strlen(essai)>25);
  834. if (strlen(essai)!=0) strcpy(tmp.ville,essai);
  835. do {
  836. printf("\nEntrer le numero de telephone prive du stagiaire\n appuyez sur ENTER si vous voulez garder %s comme telephone: ",tmp.tel);
  837. fflush(stdin);
  838. gets(essai);
  839. if (strlen(essai)>20) printf("\nVous devez entrer un numero de telephone de maximum 20 caractere" );
  840. }
  841. while (strlen(essai)>20);
  842. if (strlen(essai)!=0) strcpy(tmp.tel,essai);
  843. do {
  844. printf("\nEntrer le numero de telephone de l'entreprise du stagiaire\n appuyez sur ENTER si vous voulez garder %s comme telephone: ",tmp.tel_ent);
  845. fflush(stdin);
  846. gets(essai);
  847. if (strlen(essai)>20) printf("\nVous devez entrer un numero de telephone de maximum 20 caractere" );
  848. }
  849. while (strlen(essai)>20);
  850. if (strlen(essai)!=0) strcpy(tmp.tel_ent,essai);
  851. do
  852.    {
  853. printf ("\nEntrez le nom de l'entreprise cherchee:   " );
  854. fflush (stdin);
  855. gets (nomch);
  856. seek_ent (*ind_nm_ent,nomch,vec);
  857. rep='x';
  858. i=0;
  859. if (vec[i]!=-1)
  860.     {
  861.     while (vec[i]!=-1 && rep!='O' && rep!='A')
  862.     {
  863.     fseek (pent,vec[i]*sizeof(struct entreprise),SEEK_SET);
  864.     fread(&tmp_ent,sizeof(struct entreprise),1,pent);
  865.     clrscr();
  866.     afpent(&tmp_ent);
  867.     do {
  868.     if(vec[i+1]!=-1) printf ("\n O pour mettre cette fiche\n N pour voir la fiche suivante \n A pour Annuler: " );
  869.     else printf ("\n O pour mettre cette fiche\n A pour Annuler: " );
  870.     fflush (stdin);
  871.     rep=getchar ();
  872.     rep=toupper (rep);
  873.     }
  874.     while (rep!='A' &&  rep!='O' && rep!='N');
  875.     if (rep=='O')
  876.     {
  877.     tmp.cle_etr=tmp_ent.cle;
  878.     }
  879.     i++;
  880.     }
  881.     }
  882.   else
  883.    {
  884.    printf ("\nCe nom n'existe pas\n" );
  885.    do {
  886.     printf ("\n O pour rechercher une autre entreprise \n A pour Annuler: " );
  887.     fflush (stdin);
  888.     rep2=getchar ();
  889.     rep2=toupper (rep2);
  890.     }
  891.    while (rep2!='A' &&  rep2!='O');
  892.    }
  893. }
  894. while (rep!='O' && rep2!='A');
  895. if (rep=='O')
  896.    {
  897. do
  898.    {
  899.    printf("Etes vous sur de vouloir modifier cette fiche(o/n)?" );
  900.    fflush(stdin);
  901.    rep=getchar();
  902.    rep=tolower(rep);
  903.    }
  904. while(rep!='o' && rep!='n');
  905.    }
  906. if (rep=='o')
  907.   {
  908.   del_sta (ind_nm_sta,posi);
  909.   del_ent_sta(ind_ent_sta,old.cle_etr,posi);
  910.   fseek (psta,posi*sizeof(struct stagiaire),SEEK_SET);
  911.   fwrite(&tmp,sizeof(struct stagiaire),1,psta);
  912.   insert_sta(ind_nm_sta,tmp.cle,tmp.nom,posi);
  913.   insert_multi_ent_sta(ind_ent_sta,&tmp,posi);
  914.   }
  915. fclose(pent);
  916. fclose(psta);
  917. }
  918. /*************FONCTION DE VISUALISATION D'UN RECORD ENTREPRISE*************/
  919. afpent(struct entreprise* fiche)
  920. {
  921. printf("\nCle   : %d",fiche->cle);
  922. printf("\nNom   : %s",fiche->nom);
  923. printf("\nAddresse   : %s",fiche->addresse);
  924. printf("\nCode postale   : %d",fiche->codepost);
  925. printf("\nVille   : %s",fiche->ville);
  926. printf("\nTelephone   : %s",fiche->tel);
  927. printf("\nSecteur   : %s",fiche->secteur);
  928. }
  929. /*************FONCTION DE VISUALISATION D'UN RECORD STAGIAIRE***************/
  930. afpsta(struct stagiaire* fiche)
  931. {
  932. printf("Cle   : %d",fiche->cle);
  933. printf("\nNom   : %s",fiche->nom);
  934. printf("\nCle etrangere   : %d",fiche->cle_etr);
  935. printf("\nPrenom    : %s",fiche->prenom);
  936. printf("\nAddresse   : %s",fiche->addresse);
  937. printf("\nCode postale   : %d",fiche->codepost);
  938. printf("\nVille   : %s",fiche->ville);
  939. printf("\nTelephone prive   : %s",fiche->tel);
  940. printf("\nTelephone de l'entreprise   : %s",fiche->tel_ent);
  941. }
  942. /*********FONCTION DE VISUALISATION SEQUENTIELLE DU FICHIER ENTREPRISE******/
  943. aff_sec_ent ()
  944. {
  945. FILE *f1;
  946. struct entreprise tmp;
  947. f1=fopen(ENTR,"rb" );
  948. while(fread(&tmp,sizeof(struct entreprise),1,f1))
  949. {
  950. if(tmp.cle!=-1)
  951. {
  952. clrscr();
  953. afpent(&tmp);
  954. fflush(stdin);
  955. getch();
  956. }
  957. }
  958. }
  959. /********FONCTION DE VISUALISATION SEQUENTIELLE DU FICHIER STAGIAIRE********/
  960. aff_sec_sta ()
  961. {
  962. FILE *f1;
  963. struct stagiaire tmp;
  964. f1=fopen(STA,"rb" );
  965. while(fread(&tmp,sizeof(struct stagiaire),1,f1))
  966. {
  967. if(tmp.cle!=-1)
  968. {
  969.     clrscr();
  970. afpsta(&tmp);
  971. fflush(stdin);
  972. getch();
  973. }
  974. }
  975. }
  976. /****FONCTION DE VISUALISATION DES RECORDS ENTREPRISE INDEXE SUR LE NOM*****/
  977. afpent_ind(struct liste_ent* index)
  978. {
  979. struct entreprise tmp;
  980. FILE* f1;
  981. f1=fopen(ENTR,"rb" );
  982. while(index!=NULL)
  983.    {
  984. clrscr();
  985. fseek(f1,sizeof(struct entreprise)*index->posi,SEEK_SET);
  986. fread(&tmp,sizeof(struct entreprise),1,f1);
  987. afpent(&tmp);
  988. fflush(stdin);
  989. getch();
  990. index=index->suivant;
  991. }
  992. }
  993. /*****FONCTION DE VISUALISATION DES RECORDS STAGIAIRE INDEXE SUR LE NOM****/
  994. afpsta_ind(struct liste_sta* index)
  995. {
  996. struct stagiaire tmp;
  997. FILE *f1;
  998. f1=fopen(STA,"rb" );
  999. while(index!=NULL)
  1000. {
  1001. clrscr();
  1002. fseek(f1,sizeof(struct stagiaire)*index->posi,SEEK_SET);
  1003. fread(&tmp,sizeof(struct stagiaire),1,f1);
  1004. afpsta(&tmp);
  1005. fflush(stdin);
  1006. getch();
  1007. index=index->suivant;
  1008. }
  1009. }
  1010. /******FONCTION DE VISUALISATION DES RECORDS ENTREPRISE INDEXE SUR LE SECTEUR*/
  1011. aff_sect_ent(struct multi_ent_sect* index)
  1012. {
  1013. struct entreprise tmp;
  1014. struct liste_ent *ss_ind;
  1015. FILE* f1;
  1016. f1=fopen(ENTR,"rb" );
  1017. while(index!=NULL)
  1018.    {
  1019.    ss_ind=index->prem_ent;
  1020.    while(ss_ind!=NULL)
  1021.   {
  1022.   clrscr();
  1023.   fseek(f1,sizeof(struct entreprise)*ss_ind->posi,SEEK_SET);
  1024.   fread(&tmp,sizeof(struct entreprise),1,f1);
  1025.   printf("\nintitule du secteur:    %s\n",tmp.secteur);
  1026.   afpent(&tmp);
  1027.   fflush(stdin);
  1028.   getch();
  1029.   ss_ind=ss_ind->suivant;
  1030.   }
  1031. index=index->suivant;
  1032. }
  1033. }
  1034. /***FONCTION DE VISUALISATION DES RECORDS ENTREPRISE D'UN SECTEUR SPECIFIQUE**/
  1035. aff_sect_ent_spec(struct multi_ent_sect* index)
  1036. {
  1037. char secteur[25+1];
  1038. struct entreprise tmp;
  1039. struct liste_ent *ss_ind;
  1040. FILE* f1;
  1041. f1=fopen(ENTR,"rb" );
  1042. printf("\nEntrez le nom du secteur rechercher:   " );
  1043. fflush(stdin);
  1044. gets(secteur);
  1045. while((strcmp(index->secteur,secteur))<0 && index!=NULL)
  1046.    {
  1047.    index=index->suivant;
  1048. }
  1049. if ((strcmp(index->secteur,secteur))==0)
  1050. {
  1051. ss_ind=index->prem_ent;
  1052. while (ss_ind!=NULL)
  1053.   {
  1054.         clrscr();
  1055.   fseek(f1,sizeof(struct entreprise)*ss_ind->posi,SEEK_SET);
  1056.   fread(&tmp,sizeof(struct entreprise),1,f1);
  1057.   printf("\nintitule du secteur:    %s\n",tmp.secteur);
  1058.   afpent(&tmp);
  1059.   fflush(stdin);
  1060.   getch();
  1061.   ss_ind=ss_ind->suivant;
  1062.   }
  1063. }
  1064. else
  1065. {
  1066. printf("\naucune entreprise appartenant a ce secteur" );
  1067. fflush(stdin);
  1068. getch();
  1069. }
  1070. }
  1071. /**FONCTION DE VISUALISATION DES RECORDS STAGIAIRE INDEXE SUR L'ENTREPRISE*/
  1072. afpent_sta(struct multi_ent_sta* index)
  1073. {
  1074. struct stagiaire tmp;
  1075. struct liste_sta *ss_ind;
  1076. FILE*f1;
  1077. f1=fopen(STA,"rb" );
  1078. while(index!=NULL)
  1079.    {
  1080.    ss_ind=index->prem_sta;
  1081.    while(ss_ind!=NULL)
  1082.   {
  1083.   clrscr();
  1084.   fseek(f1,sizeof(struct stagiaire)*ss_ind->posi,SEEK_SET);
  1085.   fread(&tmp,sizeof(struct stagiaire),1,f1);
  1086.   printf("\nentreprise numero:    %d\n",tmp.cle_etr);
  1087.   afpsta(&tmp);
  1088.   fflush(stdin);
  1089.   getch();
  1090.   ss_ind=ss_ind->suivant;
  1091.   }
  1092. index=index->suivant;
  1093. }
  1094. }
  1095. /*FONCTION DE VISUALISATION DES RECORDS STAGIAIRE D'UNE ENTREPRISE SPECIFIQUE*/
  1096. afpent_sta_spec(struct multi_ent_sta* index)
  1097. {
  1098. int cle;
  1099. struct stagiaire tmp;
  1100. struct liste_sta *ss_ind;
  1101. FILE*f1;
  1102. f1=fopen(STA,"rb" );
  1103. printf("\nEntrez la cle de l'entreprise:    " );
  1104. scanf("%d",&cle);
  1105. while(index->cle_ent<cle && index!=NULL)
  1106.    {
  1107.    index=index->suivant;
  1108.    }
  1109. if (cle==index->cle_ent)
  1110.    {
  1111.    ss_ind=index->prem_sta;
  1112.    while(ss_ind!=NULL)
  1113.   {
  1114.   clrscr();
  1115.   fseek(f1,sizeof(struct stagiaire)*ss_ind->posi,SEEK_SET);
  1116.   fread(&tmp,sizeof(struct stagiaire),1,f1);
  1117.   printf("\nnumero d'entreprise:   %d\n",tmp.cle_etr);
  1118.   afpsta(&tmp);
  1119.   fflush(stdin);
  1120.   getch();
  1121.   ss_ind=ss_ind->suivant;
  1122.   }
  1123. }
  1124. else
  1125. {
  1126. printf("\nCette entreprise n'a aucun stagiaire ou n'existe pas" );
  1127. fflush(stdin);
  1128. getch();
  1129. }
  1130. }
  1131. /*******FONCTION D'AFFICHAGE DES STAGIAIRE PAR SECTEUR****************/
  1132. afpsta_sect(struct multi_ent_sect*ind_sect,struct multi_ent_sta*ind_ent_sta)
  1133. {
  1134. struct multi_ent_sta *tmp;
  1135. struct stagiaire stag;
  1136. struct liste_ent *ss_ind_ent;
  1137. struct liste_sta *ss_ind_sta;
  1138. FILE *f1;
  1139. f1=fopen(STA,"rb" );
  1140. while (ind_sect!=NULL)
  1141. {
  1142. ss_ind_ent=ind_sect->prem_ent;
  1143. while (ss_ind_ent!=NULL)
  1144.   {
  1145.   tmp=ind_ent_sta;
  1146.   while(tmp->cle_ent!=ss_ind_ent->cle && tmp!=NULL)
  1147.    {
  1148.    tmp=tmp->suivant;
  1149.    }
  1150.   if (tmp!=NULL)
  1151.    {
  1152.    ss_ind_sta=tmp->prem_sta;
  1153.    while(ss_ind_sta!=NULL)
  1154.     {
  1155.     fseek(f1,sizeof(struct stagiaire)*ss_ind_sta->posi,SEEK_SET);
  1156.     fread(&stag,sizeof(struct stagiaire),1,f1);
  1157.     clrscr();
  1158.     printf("\nintitule du secteur:   %s\n",ind_sect->secteur);
  1159.     afpsta(&stag);
  1160.     fflush(stdin);
  1161.     getch();
  1162.     ss_ind_sta=ss_ind_sta->suivant;
  1163.     }
  1164.    }
  1165.   ss_ind_ent=ss_ind_ent->suivant;
  1166.   }
  1167. ind_sect=ind_sect->suivant;
  1168. }
  1169. }
  1170. /******FONCTION D'AFFICHAGE DES STAGIAIRE D'UN SECTEUR SPECIFIQUE**********/
  1171. afpsta_sect_spec(struct multi_ent_sect*ind_sect,struct multi_ent_sta*ind_ent_sta)
  1172. {
  1173. char secteur[25];
  1174. struct multi_ent_sta *tmp;
  1175. struct stagiaire stag;
  1176. struct liste_ent *ss_ind_ent;
  1177. struct liste_sta *ss_ind_sta;
  1178. FILE *f1;
  1179. f1=fopen(STA,"rb" );
  1180. printf("\nEntrer le nom du secteur recherchee:   " );
  1181. fflush(stdin);
  1182. gets(secteur);
  1183. while (strcmp(ind_sect->secteur,secteur)<0)
  1184. {
  1185. ind_sect=ind_sect->suivant;
  1186. }
  1187. if(strcmp(ind_sect->secteur,secteur)==0)
  1188. {
  1189. ss_ind_ent=ind_sect->prem_ent;
  1190. while (ss_ind_ent!=NULL)
  1191.   {
  1192.   tmp=ind_ent_sta;
  1193.   while(tmp->cle_ent!=ss_ind_ent->cle && tmp!=NULL)
  1194.    {
  1195.    tmp=tmp->suivant;
  1196.    }
  1197.   if (tmp!=NULL)
  1198.    {
  1199.    ss_ind_sta=tmp->prem_sta;
  1200.    while(ss_ind_sta!=NULL)
  1201.     {
  1202.     fseek(f1,sizeof(struct stagiaire)*ss_ind_sta->posi,SEEK_SET);
  1203.     fread(&stag,sizeof(struct stagiaire),1,f1);
  1204.     clrscr();
  1205.     printf("\nintitule du secteur:   %s\n",ind_sect->secteur);
  1206.     afpsta(&stag);
  1207.     fflush(stdin);
  1208.     getch();
  1209.     ss_ind_sta=ss_ind_sta->suivant;
  1210.     }
  1211.    }
  1212.   ss_ind_ent=ss_ind_ent->suivant;
  1213.   }
  1214. }
  1215. else
  1216. {
  1217. printf("\naucun stagiaire appartenant a ce secteur" );
  1218. fflush(stdin);
  1219. getch();
  1220. }
  1221. }
  1222. /********FONCTION D'INSERTION D'UN RECORD ENTREPRISE DANS LA LISTE**********/
  1223. insert_ent(struct liste_ent **racine,int cle,char *nom,int posi)
  1224. {
  1225. int essai;
  1226. struct liste_ent *p_prest,*p_old;
  1227. if (*racine==NULL || strcmp (nom,(*racine)->nom)<0)
  1228. {
  1229. new_ent (nom,racine,cle,*racine,posi);
  1230. }
  1231. else
  1232. {
  1233. p_prest=(*racine)->suivant;
  1234. p_old=*racine;
  1235. while (p_prest!=NULL && strcmp (nom,p_prest->nom)>0)
  1236.    {
  1237.    p_old=p_prest;
  1238.    p_prest=p_prest->suivant;
  1239.    }
  1240. new_ent (nom,&p_old->suivant,cle,p_prest,posi);
  1241. }
  1242. }
  1243. /********FONCTION D'INSERTION D'UN RECORD STAGIAIRE DANS LA LISTE**********/
  1244. insert_sta (struct liste_sta **racine,int cle,char *nom,int posi)
  1245. {
  1246. struct liste_sta *p_prest,*p_old;
  1247. if (*racine==NULL || strcmp (nom,(*racine)->nom)<0)
  1248. {
  1249. new_sta (nom,racine,cle,*racine,posi);
  1250. }
  1251. else
  1252. {
  1253. p_prest=(*racine)->suivant;
  1254. p_old=*racine;
  1255. while (p_prest!=NULL && strcmp (nom,p_prest->nom)>0)
  1256.    {
  1257.    p_old=p_prest;
  1258.    p_prest=p_prest->suivant;
  1259.    }
  1260. new_sta (nom,&p_old->suivant,cle,p_prest,posi);
  1261. }
  1262. }
  1263. /*FONCTION D'INSERTION D'UN RECORD ENTREPRISE DANS LA MULTILISTE SECTEUR*/
  1264. insert_multi_ent_sect(struct multi_ent_sect**racine,struct entreprise* tmp,int posi)
  1265. {
  1266. struct multi_ent_sect *p_prest,*p_old;
  1267. if (*racine==NULL || strcmp (tmp->secteur,(*racine)->secteur)<0)
  1268.    {
  1269.    new_multi_ent_sect(tmp,racine,*racine,posi);
  1270.    }
  1271. else {
  1272.   if (strcmp (tmp->secteur,(*racine)->secteur)==0)
  1273.   {
  1274.   insert_ent(&(*racine)->prem_ent,tmp->cle,tmp->nom,posi);
  1275.   }
  1276.   else {
  1277.     p_prest=(*racine)->suivant;
  1278.     p_old=*racine;
  1279.     while (p_prest!=NULL && strcmp (tmp->secteur,p_prest->secteur)>0)
  1280.    {
  1281.             p_old=p_prest;
  1282.    p_prest=p_prest->suivant;
  1283.    }
  1284.     if (strcmp (tmp->secteur,(p_prest)->secteur)==0)
  1285.    {
  1286.    insert_ent(&p_prest->prem_ent,tmp->cle,tmp->nom,posi);
  1287.    }
  1288.     else {
  1289.       new_multi_ent_sect(tmp,&p_old->suivant,p_prest,posi);
  1290.       }
  1291.     }
  1292.   }
  1293. }
  1294. /***FONCTION D'INSERTION D'UN RECORD STAGIAIRE DANS LA MULTILISTE SECTEUR*/
  1295. insert_multi_ent_sta(struct multi_ent_sta**racine,struct stagiaire* tmp,int posi)
  1296. {
  1297. struct multi_ent_sta *p_prest,*p_old;
  1298. if (*racine==NULL || tmp->cle_etr<(*racine)->cle_ent)
  1299.    {
  1300.    new_multi_ent_sta(tmp,racine,*racine,posi);
  1301.    }
  1302. else {
  1303.   if ((tmp)->cle_etr==(*racine)->cle_ent)
  1304.   {
  1305.   insert_sta(&(*racine)->prem_sta,tmp->cle,tmp->nom,posi);
  1306.   }
  1307.   else {
  1308.     p_prest=(*racine)->suivant;
  1309.     p_old=*racine;
  1310.     while (p_prest!=NULL && tmp->cle_etr > p_prest->cle_ent)
  1311.    {
  1312.             p_old=p_prest;
  1313.    p_prest=p_prest->suivant;
  1314.    }
  1315.     if (tmp->cle_etr==(p_prest)->cle_ent)
  1316.    {
  1317.    insert_sta(&p_prest->prem_sta,tmp->cle,tmp->nom,posi);
  1318.    }
  1319.     else {
  1320.       new_multi_ent_sta(tmp,&p_old->suivant,p_prest,posi);
  1321.       }
  1322.     }
  1323.   }
  1324. }
  1325. /*******FONCTION D'AJOUT D'UN RECORD ENTREPRISE DANS LA LISTE**********/
  1326. new_ent (char * nom,struct liste_ent **p_old,int cle,struct liste_ent* p_next,int posi)
  1327. {
  1328. struct liste_ent *new;
  1329. new=malloc (sizeof(struct liste_ent));
  1330. strcpy (new->nom,nom);
  1331. new->suivant=p_next;
  1332. new->cle=cle;
  1333. new->posi=posi;
  1334. *p_old=new;
  1335. }
  1336. /************FONCTION D'AJOUT D'UN RECORD STAGIAIRE DANS LA LISTE*********/
  1337. new_sta (char * nom,struct liste_sta **p_old,int cle,struct liste_sta* p_next,int posi)
  1338. {
  1339. struct liste_sta *new;
  1340. new=malloc (sizeof(struct liste_sta));
  1341. strcpy (new->nom,nom);
  1342. new->suivant=p_next;
  1343. new->cle=cle;
  1344. new->posi=posi;
  1345. *p_old=new;
  1346. }
  1347. /******FONCTION D'AJOUT D'UN RECORD ENTREPRISE DANS LA MULTI LISTE********/
  1348. new_multi_ent_sect (struct entreprise *tmp,struct multi_ent_sect **p_old,struct multi_ent_sect* p_next,int posi)
  1349. {
  1350. struct multi_ent_sect *new;
  1351. new=malloc (sizeof(struct multi_ent_sect));
  1352. strcpy (new->secteur,tmp->secteur);
  1353. *p_old=new;
  1354. new->suivant=p_next;
  1355. new->prem_ent=NULL;
  1356. insert_ent(&new->prem_ent,tmp->cle,tmp->nom,posi);
  1357. }
  1358. /******FONCTION D'AJOUT D'UN RECORD STAGIAIRE DANS LA MULTI LISTE*********/
  1359. new_multi_ent_sta (struct stagiaire *tmp,struct multi_ent_sta **p_old,struct multi_ent_sta* p_next,int posi)
  1360. {
  1361. struct multi_ent_sta *new;
  1362. new=malloc (sizeof(struct multi_ent_sta));
  1363. new->cle_ent=tmp->cle_etr;
  1364. *p_old=new;
  1365. new->suivant=p_next;
  1366. new->prem_sta=NULL;
  1367. insert_sta(&new->prem_sta,tmp->cle,tmp->nom,posi);
  1368. }
  1369. /******FONCTION DE RECHERCHE D'UN RECORD ENTREPRISE BASE SUR LE NOM********/
  1370. seek_ent(struct liste_ent * index ,char *nomch,int vec [NB_SYNO])
  1371. {
  1372. int i=0;
  1373. while (index!=NULL && strcmp(nomch,index->nom)>=0 )
  1374.   {
  1375.   if (strcmp(nomch,index->nom)==0)
  1376.    {
  1377.    vec[i]=(index)->posi;
  1378.             index=index->suivant;
  1379.    i++;
  1380.    }
  1381.   else index=index->suivant;
  1382.   }
  1383. vec[i]=-1;
  1384. }
  1385. /*******FONCTION DE RECHERCHE D'UN RECORD STAGIARE BASE SUR LE NOM*******/
  1386. seek_sta(struct liste_sta * index ,char *nomch,int vec [NB_SYNO])
  1387. {
  1388. int i=0;
  1389. while (index!=NULL && strcmp(nomch,index->nom)>=0 )
  1390.   {
  1391.   if (strcmp(nomch,index->nom)==0)
  1392.    {
  1393.    vec[i]=(index)->posi;
  1394.             index=index->suivant;
  1395.    i++;
  1396.    }
  1397.   else index=index->suivant;
  1398.   }
  1399. vec[i]=-1;
  1400. }
  1401. /***FONCTION DE RECHERCHE D'UN RECORD ENTREPRISE DANS LA MULTI-LISTE*******/
  1402. int seek_ent_sta(struct multi_ent_sta* index,int cle)
  1403. {
  1404. int valid=1;
  1405. while (index!=NULL && cle<index->cle_ent)
  1406.   {
  1407.   index=index->suivant;
  1408.   }
  1409. if (cle==index->cle_ent|| index->prem_sta==NULL)valid=0;
  1410. return valid;
  1411. }
  1412. /******FONCTION DE SUPPRESION D'UN RECORD ENTREPRISE DANS LA LISTE**********/
  1413. del_ent (struct liste_ent **racine,int  a_sup)
  1414. {
  1415. struct liste_ent *p_prest,*p_old;
  1416. if (a_sup==(*racine)->posi)
  1417. {
  1418. free (*racine);
  1419. *racine=(*racine)->suivant;
  1420.   }
  1421. else
  1422. {
  1423. p_prest=(*racine)->suivant;
  1424. p_old=*racine;
  1425. while (a_sup!=p_prest->posi)
  1426.    {
  1427.    p_old=p_prest;
  1428.    p_prest=p_prest->suivant;
  1429.    }
  1430. p_old->suivant=p_prest->suivant;
  1431. free (p_prest);
  1432. }
  1433. }
  1434. /********FONCTION DE SUPPRESSION D'UN RECORD STAGIAIRE DANS LA LISTE********/
  1435. del_sta (struct liste_sta **racine,int  a_sup)
  1436. {
  1437. struct liste_sta *p_prest,*p_old;
  1438. if (a_sup==(*racine)->posi)
  1439. {
  1440. free (*racine);
  1441. *racine=(*racine)->suivant;
  1442.   }
  1443. else
  1444. {
  1445. p_prest=(*racine)->suivant;
  1446. p_old=*racine;
  1447. while (a_sup!=p_prest->posi)
  1448.    {
  1449.    p_old=p_prest;
  1450.    p_prest=p_prest->suivant;
  1451.    }
  1452. p_old->suivant=p_prest->suivant;
  1453. free (p_prest);
  1454. }
  1455. }
  1456. /*FONCTION DE SUPPRESION D'UN RECORD ENTREPRISE DANS LA MULTI-LISTE BASE SUR LE SECTEUR*/
  1457. del_multi_ent_sect(struct multi_ent_sect** index,struct entreprise*tmp,int posi)
  1458. {
  1459. struct multi_ent_sect *p_prest,*p_old;
  1460. if (strcmp((*index)->secteur,tmp->secteur)==0)
  1461. {
  1462. del_ent(&(*index)->prem_ent,posi);
  1463. if ((*index)->prem_ent==NULL)
  1464.     {
  1465.     free (*index);
  1466.     *index=(*index)->suivant;
  1467.     }
  1468. }
  1469. else
  1470. {
  1471. p_prest=(*index)->suivant;
  1472. p_old=*index;
  1473. while (strcmp(p_prest->secteur,tmp->secteur)!=0)
  1474.    {
  1475.    p_old=p_prest;
  1476.    p_prest=p_prest->suivant;
  1477.    }
  1478. del_ent(&(p_prest->prem_ent),posi);
  1479. if (p_prest->prem_ent==NULL)
  1480.   {
  1481. p_old->suivant=p_prest->suivant;
  1482. free (p_prest);
  1483.   }
  1484. }
  1485. }
  1486. /*FONCTION DE SUPPRESION D'UN RECORD STAGIARE DANS LA MULTI-LISTE BASE SUR LES ENTREPRISE*/
  1487. del_ent_sta(struct multi_ent_sta** index,int cle_etr,int posi)
  1488. {
  1489. struct multi_ent_sta *p_prest,*p_old;
  1490. if ((*index)->cle_ent==cle_etr)
  1491. {
  1492. del_sta(&(*index)->prem_sta,posi);
  1493. if ((*index)->prem_sta==NULL)
  1494.     {
  1495.     free (*index);
  1496.     *index=(*index)->suivant;
  1497.     }
  1498. }
  1499. else
  1500. {
  1501. p_prest=(*index)->suivant;
  1502. p_old=*index;
  1503. while (p_prest->cle_ent!=cle_etr)
  1504.    {
  1505.    p_old=p_prest;
  1506.    p_prest=p_prest->suivant;
  1507.    }
  1508. del_sta(&(p_prest->prem_sta),posi);
  1509. if (p_prest->prem_sta==NULL)
  1510.   {
  1511. p_old->suivant=p_prest->suivant;
  1512. free (p_prest);
  1513.   }
  1514. }
  1515. }
  1516. /*******FONCTION D'AJOUT D'UN ELEMENT DANS LA PILE ENTREPRISE************/
  1517. push_ent (struct ple_ent **p_sup,int posi)
  1518. {
  1519. struct ple_ent *new;
  1520. new=malloc (sizeof(struct ple_ent));
  1521. new->suivant=(*p_sup);
  1522. new->posi=posi;
  1523. *p_sup=new;
  1524. }
  1525. /********FONCTION D'AJOUT D'UN ELEMENT DANS LA PILE ENTREPRISE************/
  1526. push_sta (struct ple_sta **p_sup,int posi)
  1527. {
  1528. struct ple_sta *new;
  1529. new=malloc (sizeof(struct ple_sta));
  1530. new->suivant=(*p_sup);
  1531. new->posi=posi;
  1532. *p_sup=new;
  1533. }
  1534. /********FONCTION DE SUPPRESION D'UN ELEMENT DE LA PILE ENTREPRISE********/
  1535. pop_ent (struct ple_ent **p_sup)
  1536. {
  1537. struct ple_ent *tmp;
  1538. tmp=(*p_sup)->suivant;
  1539. free (*p_sup);
  1540. *p_sup=tmp;
  1541. }
  1542. pop_sta (struct ple_sta **p_sup)
  1543. {
  1544. struct ple_sta *tmp;
  1545. tmp=(*p_sup)->suivant;
  1546. free (*p_sup);
  1547. *p_sup=tmp;
  1548. }
  1549. /**********FONCTION DE REORGANISATION DU FICHIER***********************/
  1550. reorga(struct liste_ent **ind_nm_ent,struct liste_sta **ind_nm_sta,struct multi_ent_sect **ind_sect_ent,struct multi_ent_sta **ind_ent_sta,struct ple_ent **pile_ent,struct ple_sta **pile_sta)
  1551. {
  1552. struct entreprise tmp_ent;
  1553. struct stagiaire tmp_sta;
  1554. int i;
  1555. FILE *psta;
  1556. FILE *pent;
  1557. pent=fopen(ENTR,"rb" );
  1558. psta=fopen(STA,"rb" );
  1559. i=0;
  1560. while (fread(&tmp_ent,sizeof(struct entreprise),1,pent))
  1561. {
  1562. if (tmp_ent.cle!=-1)
  1563.     {
  1564.   insert_ent(ind_nm_ent,tmp_ent.cle,tmp_ent.nom,i);
  1565.   insert_multi_ent_sect(ind_sect_ent,&tmp_ent,i);
  1566.   }
  1567. else
  1568.   {
  1569.   push_ent(pile_ent,i);
  1570.   }
  1571. i++;
  1572. }
  1573. i=0;
  1574. while (fread(&tmp_sta,sizeof(struct stagiaire),1,psta))
  1575. {
  1576. if (tmp_sta.cle!=-1)
  1577.     {
  1578.   insert_sta(ind_nm_sta,tmp_sta.cle,tmp_sta.nom,i);
  1579.   insert_multi_ent_sta(ind_ent_sta,&tmp_sta,i);
  1580.   }
  1581. else
  1582.   {
  1583.   push_sta(pile_sta,i);
  1584.   }
  1585. i++;
  1586. }
  1587. fclose (pent);
  1588. fclose(psta);
  1589. }
  1590. /*********************FONCTION DE COMPACTAGE **************************/
  1591. compact(struct liste_ent **ind_nm_ent,struct liste_sta **ind_nm_sta,struct multi_ent_sect **ind_sect_ent,struct multi_ent_sta **ind_ent_sta,struct ple_ent**pile_ent,struct ple_sta**pile_sta)
  1592. {
  1593. int i,j;
  1594. FILE * f_tmp;
  1595. FILE *psta;
  1596. FILE *pent;
  1597. struct liste_ent *ent;
  1598. struct liste_sta *sta;
  1599. struct entreprise tmp_ent;
  1600. struct stagiaire tmp_sta;
  1601. struct temp tmp_temp;
  1602. char nom[50];
  1603. while(*pile_ent!=NULL)
  1604. {
  1605. pop_ent(pile_ent);
  1606. }
  1607. while(*pile_sta!=NULL)
  1608. {
  1609. pop_sta(pile_sta);
  1610. }
  1611. while(*ind_nm_ent!=NULL)
  1612. {
  1613. free(*ind_nm_ent);
  1614. *ind_nm_ent=(*ind_nm_ent)->suivant;
  1615. }
  1616. while(*ind_nm_sta!=NULL)
  1617. {
  1618. free(*ind_nm_sta);
  1619. *ind_nm_sta=(*ind_nm_sta)->suivant;
  1620. }
  1621. pent=fopen(ENTR,"rb" );
  1622. while (*ind_sect_ent!=NULL)
  1623. {
  1624. ent=(*ind_sect_ent)->prem_ent;
  1625. fseek(pent,sizeof(struct entreprise)*ent->posi,SEEK_SET);
  1626. fread(&tmp_ent,sizeof(struct entreprise),1,pent);
  1627. del_multi_ent_sect(ind_sect_ent,&tmp_ent,ent->posi);
  1628. }
  1629. while (*ind_ent_sta!=NULL)
  1630. {
  1631. sta=(*ind_ent_sta)->prem_sta;
  1632. del_ent_sta(ind_ent_sta,(*ind_ent_sta)->cle_ent,sta->posi);
  1633. }
  1634. i=0;
  1635. rewind(pent);
  1636. f_tmp=fopen(TMP,"wb" );
  1637. while (fread(&tmp_ent,sizeof(struct entreprise),1,pent))
  1638. {
  1639. if (tmp_ent.cle!=-1)
  1640.     {
  1641.   insert_ent(ind_nm_ent,tmp_ent.cle,tmp_ent.nom,i);
  1642.   insert_multi_ent_sect(ind_sect_ent,&tmp_ent,i);
  1643.   fwrite(&tmp_ent,sizeof(struct entreprise),1,f_tmp);
  1644.   i++;
  1645.   }
  1646. }
  1647. fclose(pent);
  1648. fclose(f_tmp);
  1649. remove(ENTR);
  1650. rename(TMP,ENTR);
  1651. j=0;
  1652. f_tmp=fopen(TMP,"wb" );
  1653. psta=fopen(STA,"rb" );
  1654. while (fread(&tmp_sta,sizeof(struct stagiaire),1,psta))
  1655. {
  1656. if (tmp_sta.cle!=-1)
  1657.     {
  1658.   insert_sta(ind_nm_sta,tmp_sta.cle,tmp_sta.nom,j);
  1659.   insert_multi_ent_sta(ind_ent_sta,&tmp_sta,j);
  1660.   fwrite(&tmp_sta,sizeof(struct stagiaire),1,f_tmp);
  1661.   j++;
  1662.   }
  1663. }
  1664. fclose(psta);
  1665. fclose(f_tmp);
  1666. remove(STA);
  1667. rename(TMP,STA);
  1668. f_tmp=fopen(TEMP,"r+b" );
  1669. fread(&tmp_temp,sizeof(struct temp),1,f_tmp);
  1670. tmp_temp.posi_ent=i;
  1671. tmp_temp.posi_ent=j;
  1672. rewind(f_tmp);
  1673. fwrite(&tmp_temp,sizeof(struct temp),1,f_tmp);
  1674. fclose(f_tmp);
  1675. }


 
 
ne me remerciez pas ca m'a fait plaisir [:dawa]

n°437322
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 23-06-2003 à 14:28:14  profilanswer
 

RiderCrazy a écrit :

Editer ça te dit quelque chose...

c'est pas l'auteur du topic


---------------
J'ai un string dans l'array (Paris Hilton)
n°437323
kadreg
profil: Utilisateur
Posté le 23-06-2003 à 14:29:05  profilanswer
 

GCS suxorize :o


---------------
brisez les rêves des gens, il en restera toujours quelque chose...  -- laissez moi troller sur discu !
n°437324
chrisbk
-
Posté le 23-06-2003 à 14:29:55  profilanswer
 

Ah ben voila tiens, on veut aider les autres a comprendre ce magnifique bout de code, veritable hommage au langage C tant il est propre et astucieux, et voila comment on se fait accueillir :O

n°437325
RiderCrazy
Posté le 23-06-2003 à 14:30:23  profilanswer
 

Harkonnen a écrit :

c'est pas l'auteur du topic

Dsl, j'ai capté qu'après... désolé chrisbk

n°437326
Loom the G​loom
Even coders get the blues...
Posté le 23-06-2003 à 14:32:01  profilanswer
 

Harkonnen a écrit :

ben je viens de dire que c'était bruno [:sinclaire]


 
ah oui  :D


---------------
Music|Market|Feed|Loom|DVD
n°437327
Taz
bisounours-codeur
Posté le 23-06-2003 à 15:01:02  profilanswer
 

ton code est mité... rien que les fflush(stdin) ça en dit long. au fait, tu sais ce que c'est que la gestion d'erreur?

n°437328
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 23-06-2003 à 15:02:16  profilanswer
 

++Taz a écrit :

ton code est mité... rien que les fflush(stdin) ça en dit long. au fait, tu sais ce que c'est que la gestion d'erreur?

laisse couler, c'est un type spécialisé dans le troll et les farces de mauvais gout ;)
j'ai envie de jouer au ping-pong avec ce topic [:cupra]


---------------
J'ai un string dans l'array (Paris Hilton)
n°437329
chrisbk
-
Posté le 23-06-2003 à 15:04:08  profilanswer
 

Harkonnen a écrit :

laisse couler, c'est un type spécialisé dans le troll et les farces de mauvais gout ;)
j'ai envie de jouer au ping-pong avec ce topic [:cupra]


 
tiens oui, ca pourrait les interesser sur overclocking un topic de cette qualité :jap:

mood
Publicité
Posté le   profilanswer
 

 Page :   1  2
Page Précédente

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation

  je vous donne mon programme

 

Sujets relatifs
Comment faire d'une solution VBA un programme .exe ?Problème avec un programme de sauvegarde périodique
Programme con [Editeur HFR]Decouper mon programme en plusieur unites.
n'autoriser qu'une seule exécution simultanée d'un programmeprogramme de compilation
Programme --> Clique automatiqueLe premier qui me fait se programme !!!!!
Comment récupérer les numéros de tel entrants dans un programme C++ ?Comment exécuter un programme à partir du VBA dans excel
Plus de sujets relatifs à : je vous donne mon programme


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR