You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
226 lines
5.2 KiB
226 lines
5.2 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include "../partie1/saeP1.h"
|
|
#include "saeAnnexe.h"
|
|
|
|
void menu(void){
|
|
printf("#--------------------------------------------------------------------#\n");
|
|
printf("| |\n");
|
|
printf("| Menu de la SAE S1.02 |\n");
|
|
printf("| |\n");
|
|
printf("#--------------------------------------------------------------------#\n\n");
|
|
printf("Codes pour accéder aux différents profils :\n\n");
|
|
printf("C : Consultation.\n");
|
|
printf("A : Administrateur.\n");
|
|
printf("S : Sauvegarder.\n\n");
|
|
printf("#--------------------------------------------------------------------#\n\n");
|
|
printf("Choisissez votre session : ");
|
|
}
|
|
|
|
int loadIUT(VilleIUT** tiut){
|
|
FILE* f=fopen("Etudiants.bin","rb");
|
|
if(f==NULL){
|
|
perror("fopen");
|
|
exit(errno);
|
|
}
|
|
MaillonDep* m;
|
|
int tlogi;
|
|
fread(&tlogi,sizeof(int),1,f);
|
|
for(int i=0; i<tlogi; i++){
|
|
fread(tiut[i]->Ville,sizeof(char),31,f);
|
|
}
|
|
for(int i=0; i<tlogi; i++){
|
|
int nbIUTs;
|
|
fread(&nbIUTs,sizeof(int),1,f);
|
|
if(nbIUTs){
|
|
tiut[i]->ldept=(MaillonDep*)malloc(sizeof(MaillonDep));
|
|
if(tiut[i]->ldept==NULL){
|
|
perror("malloc");
|
|
exit(errno);
|
|
}
|
|
}
|
|
m=tiut[i]->ldept;
|
|
for(int j=0; j<nbIUTs; j++){
|
|
fread(m->departement,sizeof(char),31,f);
|
|
fread(&m->nbp,sizeof(int),1,f);
|
|
fread(m->resp,sizeof(char),51,f);
|
|
if(j<nbIUTs-1){
|
|
m->suivant=(MaillonDep*)malloc(sizeof(MaillonDep));
|
|
if(m->suivant==NULL){
|
|
perror("malloc");
|
|
exit(errno);
|
|
}
|
|
m=m->suivant;
|
|
}
|
|
}
|
|
}
|
|
return tlogi;
|
|
}
|
|
|
|
void saveIUT(VilleIUT** tiut, int tlogi){
|
|
FILE* f=fopen("Etudiants.bin","rb");
|
|
if(f==NULL){
|
|
perror("fopen");
|
|
exit(errno);
|
|
}
|
|
MaillonDep* m;
|
|
fwrite(&tlogi,sizeof(int),1,f)
|
|
for(int i=0; i<tlogi; i++){
|
|
fwrite(tiut[i]->ville,sizeof(char),31,f);
|
|
}
|
|
for(int i=0; i<tlogi; i++){
|
|
int nbIUTs=longueurListe(tiut[i]->ldept);
|
|
fwrite(&nbIUTs,sizeof(int),1,f);
|
|
m=tiut[i]->ldept;
|
|
for(int j=0; j<nbIUTs; j++){
|
|
fwrite(m->departement,sizeof(char),31,f);
|
|
fwrite(&m->nbp,sizeof(int),1,f);
|
|
fwrite(m->resp,sizeof(char),51,f);
|
|
m=m->suivant;
|
|
}
|
|
}
|
|
printf("Les IUTs enregistrés ont bien étés sauvegardés.");
|
|
}
|
|
|
|
int rechercheTabPtVilleIUT(VilleIUT* tab[],int lTab,char* mot){
|
|
if(!lTab){
|
|
fprintf(stderr,"Erreur, Pas d'éléments dans le tableau !");
|
|
return -1;
|
|
}
|
|
for(int i=0; i<lTab;i++){
|
|
if(tab[i]->Ville==mot) return i;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
//Listes chainées
|
|
int existeDep(MaillonDep* liste, char* dep){
|
|
MaillonDep* m=liste;
|
|
while(m->suivant!=NULL){
|
|
if(!strcmp(m->departement,dep)){
|
|
return 1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int longueurListe(MaillonDep* liste){
|
|
MaillonDep* m=liste;
|
|
int i=0;
|
|
while(m!=Null){
|
|
m=m->suivant;
|
|
i++;
|
|
}
|
|
return i;
|
|
}
|
|
|
|
//Pile
|
|
Pile creerpile(int tmax)
|
|
{
|
|
Pile p=(Pile)malloc(sizeof(pile));
|
|
p->tlogi=0;
|
|
p->tmax=tmax;
|
|
p->tab=(int*) malloc(tmax);
|
|
return p;
|
|
}
|
|
|
|
void empiler(Pile p, int x)
|
|
{
|
|
if (p->tmax==p->tlogi)
|
|
{
|
|
printf("Pile pleine");
|
|
return;
|
|
}
|
|
p->tab[p->tlogi++]=x;
|
|
}
|
|
|
|
void afficherPileEntier(Pile p)
|
|
{
|
|
for (int i=0; i<p->tlogi;i++) printf("%d\n",p->tab[i]);
|
|
}
|
|
|
|
int depiler(Pile p)
|
|
{
|
|
if (p->tlogi==0)
|
|
{
|
|
printf("Pile vide");
|
|
return -1;
|
|
}
|
|
return p->tab[--(p->tlogi)];
|
|
}
|
|
|
|
//File
|
|
File creerfile(int tmax)
|
|
{
|
|
File f=(File)malloc(sizeof(file));
|
|
Pile inipEntry=(Pile)malloc(sizeof(pile)/2);
|
|
Pile inipExit=(Pile)malloc(tmax-sizeof(pile)/2);
|
|
if (f==NULL || inipEntry==NULL || inipExit==NULL)
|
|
{
|
|
printf("Erreur maloc ini file\n");
|
|
exit(1);
|
|
}
|
|
|
|
inipEntry->tlogi=0;
|
|
inipEntry->tmax=tmax;
|
|
inipEntry->tab=(int*) malloc(tmax);
|
|
|
|
inipExit->tlogi=0;
|
|
inipExit->tmax=tmax-tmax/2;
|
|
inipExit->tab=(int*) malloc(tmax);
|
|
|
|
f->pEntry=inipEntry;
|
|
f->pExit=inipExit;
|
|
return f;
|
|
}
|
|
|
|
void vider_file(File f)
|
|
{
|
|
while (f->pExit->tmax!=f->pExit->tlogi && f->pEntry->tlogi!=0)
|
|
{
|
|
empiler(f->pExit,depiler(f->pEntry));
|
|
}
|
|
}
|
|
|
|
void enfiler(File f, int x)
|
|
{
|
|
if (f->pEntry->tlogi==f->pEntry->tmax)
|
|
{
|
|
vider_file(f);
|
|
}
|
|
f->pEntry->tab[f->pEntry->tlogi]=x;
|
|
f->pEntry->tlogi++;
|
|
}
|
|
|
|
int defiler(File f)
|
|
{
|
|
if (f->pExit->tlogi==0)
|
|
{
|
|
vider_file(f);
|
|
}
|
|
|
|
if (f->pExit->tlogi==0)
|
|
{
|
|
printf("File vide");
|
|
return -1;
|
|
}
|
|
|
|
f->pExit->tlogi--;
|
|
return f->pExit->tab[f->pExit->tlogi];
|
|
}
|
|
|
|
void afficherFileEntier(File f)
|
|
{
|
|
for(int i=0;i<f->pExit->tlogi;++i) printf("%d\n",f->pExit->tab[i]);
|
|
for(int i=f->pEntry->tlogi;i!=0;--i) printf("%d\n",f->pEntry->tab[i]);
|
|
}
|
|
|
|
void reset(void){
|
|
char capt;
|
|
printf("\n\nAppuyez sur entrer pour continuer :\n");
|
|
scanf("%*c%c",&capt);
|
|
system("clear");
|
|
}
|