1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#include <stdio.h>
#include <stdlib.h>
#include "note.h"
#include <string.h>
struct note* saisie_bulletin(){
int nbUE, i=0;
struct note* tab;
struct note marqueur={-1,-1};
printf("Combien d'Unités de Valeurs voulez vous creer ?\n Entrez un entier.");
scanf("%d",&nbUE);
printf("La fonction va creer un tableu contenant autant de cases que vous avez demandez.\n");
tab= (struct note*)malloc((nbUE+1)*sizeof(struct note*));
if(tab == NULL){ return tab;}
/*La derniere case est a -1 : elle marque la fin du tableau*/
*(tab+nbUE+1)=marqueur;
/* Initialisation du tableau*/
printf("Entrez les notes de l'etudiant:");
while(i < nbUE){
printf("Entrez l'ue concernée :");
scanf("%d", &(tab[i].ue));
printf("Entrez la note :");
scanf("%d", &(tab[i].note));
while (tab[i].note < 0 || tab[i].note >20){
printf("Mauvaise saisie.\nRecommencez.");
scanf("%d", &(tab[i].note));
}
i++;
}
return tab;
}
struct etudiant saisie_etudiant(){
struct etudiant etu;
char *s;
int saisieok=0;
s= (char*)malloc((9)*sizeof(char));
printf("Vous allez entrer le nom et la note d'un etudiant.\n");
printf("Entrez le nom :\n");
scanf("%s", s);
s[9]=0;
etu.nom=s;
free(s);
while(strlen(etu.nom) > 9){
printf("Mauvaise saisie : nom trop long.\n");
scanf("%s", s);
s[9]=0;
etu.nom=s;
free(s);
}
printf("Entrez les notes de cet etudiant.\n");
etu.liste=saisie_bulletin();
return etu;
}
struct etudiant* saisie_promo(){
struct etudiant* promo;
struct etudiant saisie;
int i=0, taillepromo=50,test=1;
/*Initialisation du tableu*/
promo= (struct etudiant*)malloc((taillepromo)*sizeof(struct etudiant));
perror("Erreur lors de la creation du tableau promo.\n");
/*Creation du tableau promo*/
printf("Si vous etes arrivé à la fin de votre promo, entrez un nouvel etudiant dont le nom vaut NULL.\n");
while(test!=0){
saisie=saisie_etudiant();
promo[i]=saisie;
if(i%taillepromo==0){
taillepromo += 25;
realloc(promo,taillepromo*sizeof(struct etudiant*));
perror("Erreur lors de la reallocation de la promotion.");
}
test=strcmp(saisie.nom, "NULL");
i++;
}
/*Test*/
printf("Fin de la saisie de la promotion.\n");
while(1){i++;}
return promo;
}
struct note{
int ue;
int note;
};
struct etudiant {
char *nom;
struct note *liste;
};
struct note* saisie_bulletin();
struct etudiant saisie_etudiant();
struct etudiant* saisie_promo();
#include "note.h"
int main(){
/*saisie_bulletin();*/
/*saisie_etudiant();*/
saisie_promo();
return 0;
} |
Partager