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.
346 lines
7.7 KiB
346 lines
7.7 KiB
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include "sae1-02.h"
|
|
|
|
// général
|
|
|
|
// f enregistrement
|
|
|
|
// Partie 1
|
|
/*
|
|
|
|
void affichageVilleIUT() {
|
|
printf("%s\t%s\t%d\t%s")
|
|
}
|
|
|
|
int rechercheVille() {
|
|
|
|
}
|
|
|
|
VilleIUT lire(FILE * fe) {
|
|
VilleIUT v;
|
|
fscanf(fe, "%s", V.ville);
|
|
fscanf(fe, "%s", v.Idept->departement);
|
|
fscanf(fe, "%d", v.Idept->nbplace);
|
|
fgets(v.Idept->responsable, 31, fe);
|
|
v.Idept->responsable[strlen(v.Idept->responsable)-1] = '\0';
|
|
return v;
|
|
}
|
|
*/
|
|
// Partie 2
|
|
|
|
/*
|
|
|- décision ( admis - 1 /attente 0 default /refusé -2 )
|
|
|- validation candidat ( 0 default / -1 refus de ce choix / 2 accepte )
|
|
|
|
combien de fonctionnalité en combien de fonction ...
|
|
|
|
V charger fichier
|
|
V ajouter choix
|
|
- modifier choix
|
|
- supp choix
|
|
V enregistrer fichier
|
|
- section affichage
|
|
|
|
*/
|
|
|
|
//chargement ============================================================================================
|
|
|
|
Listchoixdept listvide(void){return NULL;}
|
|
|
|
Listchoixdept lireCarte(FILE *fe, int nbchoix){
|
|
if(nbchoix==0){return NULL;}
|
|
Maillonchoix* cc;
|
|
cc = (Maillonchoix*)malloc(sizeof(Maillonchoix));
|
|
fscanf(fe, "%s %s %d %d", cc->Ville, cc->dep, &cc->decision, &cc->validation);
|
|
cc->suivant = lireCarte(fe, nbchoix-1);
|
|
return cc;
|
|
}
|
|
|
|
listetuinfo lireEtu(FILE *fe){
|
|
listetuinfo b;
|
|
int i;
|
|
fscanf(fe, "%d %s %s %d %d %d %d %d", &b.numeroetu, b.nometu, b.prenometu, &b.notes[0], &b.notes[1], &b.notes[2], &b.notes[3], &b.nbchoix);
|
|
return b;
|
|
}
|
|
|
|
int chargeretudiant(char nomFich[], listetuinfo *tetu[], int tmax){
|
|
int i=0, nbetu;
|
|
listetuinfo a;
|
|
Listchoixdept b;
|
|
FILE *fe;
|
|
fe = fopen( nomFich, "r");
|
|
if(fe==NULL){printf("<! pb ouverture fichier in chargeretudiant !>\n");return-1;}
|
|
fscanf(fe, "%d", &nbetu);
|
|
b = listvide();
|
|
for(i=0; i<nbetu; i++){
|
|
if(i==tmax){printf("<! erreur fichier in chargeetudiant !>");fclose(fe);return-1;}
|
|
tetu[i] = (listetuinfo*)malloc(sizeof(listetuinfo));
|
|
if(tetu[i]==NULL){printf("<! pb malloc in chargeretudiant !>\n");fclose(fe);return-1;}
|
|
a = lireEtu(fe);
|
|
b = lireCarte(fe, a.nbchoix);
|
|
a.carte = b;
|
|
*tetu[i] = a;
|
|
}
|
|
fclose(fe);
|
|
return nbetu;
|
|
}
|
|
|
|
//enregistrement ========================================================================================
|
|
|
|
void enregistrementcarte(FILE *fe, Maillonchoix* b){
|
|
if(b==NULL){return;}
|
|
fprintf(fe, "%s\n%s\n%d\n%d\n", b->Ville, b->dep, b->decision, b->validation);
|
|
enregistrementcarte(fe, b.suivant, nb-1);
|
|
free(b);
|
|
}
|
|
|
|
void enregistrementinfo(FILE *fe, listetuinfo etu){
|
|
Listchoixdept b;
|
|
int i=0;
|
|
b = etu.carte;
|
|
fprintf(fe, "%d\n%s\n%s\n%d %d %d %d\n%d\n", etu->numeroetu, etu->nometu, etu->prenometu, etu->notes, etu->nbchoix);
|
|
enregistrementcarte(fe, b, etu.nbchoix);
|
|
}
|
|
|
|
int enregistrementetudiant(char nomFich[], listetuinfo *tetu[], int nb){
|
|
int i=0;
|
|
FILE *fe;
|
|
fe = fopen( nomFich, "w");
|
|
if(fe==NULL){printf("<! pb fichier in enregistrementetudiant !>\n");return-1;}
|
|
fprintf(fe, "%d\n", nb);
|
|
for(i=0; i<nb; i++){
|
|
enregistrementinfo(fe, tetu[i]);
|
|
free(tetu[i]);
|
|
}
|
|
fclose(fe);
|
|
}
|
|
|
|
//ajouter ===============================================================================================
|
|
// sous-partie -> affichage tville avec uniquement les dep ===========
|
|
|
|
void affichagedep(MaillonDept* b){
|
|
if(b==NULL){return;}
|
|
printf("%s", b->departement);
|
|
affichagedep(b.suivant);
|
|
}
|
|
|
|
void affichageville(Maillon *tville[], int nbville){
|
|
int i;
|
|
Listdept b;
|
|
for(i=0; i<nbville; i++){
|
|
b = tville[i].ldept;
|
|
printf("%s :\n", tville[i]->Ville);
|
|
affichagedep(b);
|
|
printf("\n");
|
|
}
|
|
}
|
|
|
|
//========================== -fin de sous-partie
|
|
|
|
int cherchelistcorrespond(MaillonDept* b, char choixdep[]){
|
|
if(b==NULL){return -1}
|
|
if(strcmp(b->departement,choixdep)==0){return 1;}
|
|
return cherchelistcorrespond(b.suivant);
|
|
}
|
|
|
|
int correspond(Maillon *tville[], int nbville, char choixville[], char choixdep[]){
|
|
int i;
|
|
Listdept b;
|
|
for(i=0; i<nbville; i++){
|
|
if(strcmp(tville[i]->Ville,choixville)==0){
|
|
b = tville[i].ldept;
|
|
ok = cherchelistcorrespond(b, choixdep);
|
|
if(ok==1){return 1;}
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void affichechoix(Maillon *tville[], int nbville, char choixville[], char choixdep[]){
|
|
affichageville(tville);
|
|
printf("ville : ");
|
|
fgets(choixville, 31, stdin);
|
|
choixville[strlen(choixville)-1]='\0';
|
|
fgets(choixdep, 31, stdin);
|
|
choixdep[strlen(choixdep)-1]='\0';
|
|
ok = correspond(tville, nbville, choixville, choixdep);
|
|
while(ok=-1){
|
|
affichageville(tville);
|
|
printf("ville : ");
|
|
fgets(choixville, 31, stdin);
|
|
choixville[strlen(choixville)-1]='\0';
|
|
fgets(choixdep, 31, stdin);
|
|
choixdep[strlen(choixdep)-1]='\0';
|
|
ok = correspond(tville, nbville, choixville, choixdep);
|
|
}
|
|
}
|
|
|
|
int verifdoublon(char choixville[], char choixdep[], Maillonchoix* b){
|
|
if(b==NULL){return 0;}
|
|
if(strcmp(choixville,b->Ville)==0){
|
|
if(strcmp(choixdep,b->departement)==0){
|
|
return -1
|
|
}
|
|
}
|
|
}
|
|
|
|
Listchoixdept ajoutercarte(Maillonchoix* a, char choixville, char choixdep){
|
|
Maillonchoix* carte;
|
|
carte = (Maillonchoix*)malloc(sizeof(Maillonchoix));
|
|
if(carte==NULL){printf("<! erreur malloc in ajoutercarte !>\n");exit(1);}
|
|
strcpy(carte->Ville,choixville);
|
|
strcpy(carte->departement,choixdep);
|
|
carte->decision=0;
|
|
carte->validation=0;
|
|
carte->suviant=a;
|
|
return carte;
|
|
}
|
|
|
|
int allajoutprocess(Maillon *tville[], listetuinfo etu, int nbville){
|
|
int i;
|
|
Listchoixdept b;
|
|
b = etu.carte;
|
|
char choixville[31], choixdep[31];
|
|
affichechoix(tville, nbville, choixville, choixdep);
|
|
ok = verifdoublon(choixville, choixdep, b);
|
|
if(ok==0){b = ajoutercarte(b, choixville, choixdep);}
|
|
else{printf("\t< choix deja existant >\n");}
|
|
}
|
|
|
|
//modifier ==============================================================================================
|
|
|
|
// modification par ville ou par dep
|
|
|
|
|
|
|
|
|
|
//supprimer =============================================================================================
|
|
|
|
//affichage =============================================================================================
|
|
|
|
//=======================================================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// zone de test ============================================================================================
|
|
|
|
//affiche uniquement les cartes (choix d'iut)
|
|
void affichage(Listchoixdept c){
|
|
if(c==NULL){printf("\n");return;}
|
|
printf("%s %s %d %d", c->Ville, c->dep, c->decision, c->validation);
|
|
if(c->suivant==NULL){affichage(c->suivant);}
|
|
else{
|
|
printf("\n -");
|
|
affichage(c->suivant);
|
|
}
|
|
}
|
|
|
|
//affiche que la personne
|
|
void affichageetu(listetuinfo a){
|
|
printf(" %d\n %s %s\n", a.numeroetu, a.nometu, a.prenometu);
|
|
printf(" mathématique : %d\n", a.notes[0]);
|
|
printf(" français : %d\n", a.notes[1]);
|
|
printf(" anglais : %d\n", a.notes[2]);
|
|
printf(" matière spé : %d\n", a.notes[3]);
|
|
}
|
|
|
|
//affichage general
|
|
void affichealletu(listetuinfo *tetu[], int nb){
|
|
int j=0;
|
|
Listchoixdept b;
|
|
b = listvide();
|
|
for(j=0; j<nb; j++){
|
|
affichageetu(*tetu[j]);
|
|
printf("tout les choix : \n -");
|
|
b = tetu[j]->carte;
|
|
affichage(b);
|
|
printf("\n\n");
|
|
}
|
|
}
|
|
|
|
void test1(void){
|
|
listetuinfo *tetu[5000];
|
|
int nb;
|
|
char nomFich[20];
|
|
strcpy( nomFich, "candidature.txt");
|
|
nb = chargeretudiant(nomFich, tetu, 5000);
|
|
affichealletu(tetu, nb);
|
|
}
|
|
|
|
//==========================================================================================================
|
|
|
|
// Partie 3
|
|
|
|
// Partie 4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Général (menu et ce qui en ai relié)
|
|
/*
|
|
questionadmin(){
|
|
printf("\nQuel numéro détudiant ?\n==>");
|
|
scanf("%d%*c", &choix);
|
|
printf("\n");
|
|
}
|
|
|
|
int menu(void){
|
|
|
|
|
|
//charger
|
|
|
|
|
|
int i=0, choix;
|
|
while(i!=1){
|
|
printf("\n\tmenu\n\n");
|
|
printf("1\tutilisateur\n");
|
|
printf("2\tadmin\n");
|
|
printf("3\tresponsable d'admission\n");
|
|
printf("\nQuel est votre choix ?\n==>");
|
|
scanf("%d%*c", &choix);
|
|
printf("\n");
|
|
if(choix==1){
|
|
}
|
|
if(choix==2){
|
|
}
|
|
if(choix==3){
|
|
}
|
|
if(choix<1 || choix>6){
|
|
printf("mauvaise saisie\n");
|
|
}
|
|
}
|
|
|
|
//enregister
|
|
|
|
return 1;
|
|
}
|
|
*/
|