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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define MAX 100
typedef struct Date Date;
typedef struct Etudiant Etd;
typedef struct Cellule liste;
void debuff();
void cls();
short int invalid_date (Date testdate);
void scan_etd( Etd * student);
void print_etd ( Etd student);
struct Date
{
int jj;
int mm;
int aa;
} ;
struct Etudiant
{
int ID;
char name[20];
Date date;
int note;
};
struct Cellule
{
Etd student;
liste*suivant;
};
void debuff()
{
while (getchar()!='\n');
}
void cls()
{
system("cls");
}
short int invalid_date (Date testdate)
{
short int Restart=0;
int A;
A=testdate.jj;
if (A<0 || A>31) Restart=1;
A=testdate.mm;
if (A<0 || A>12) Restart=1;
A=testdate.aa;
if (A<0 || A>2016) Restart=1;
return Restart;
}
void scan_etd( Etd * student)
{
do /*** Lecture ID ****/
{
cls();
printf("\n ID : \t");
scanf("%d",&student->ID);
debuff();
} while (student->ID<0 || student->ID>20);
/**Nom**/ printf("\n Nom :\t"); scanf("%s",student->name);
do /*** Lecture DateNaiss ****/
{
cls();
printf("\n Date Naissance (jj mm aa) :\t");
scanf("%d%d%d",&student->date.jj,&student->date.mm,&student->date.aa);
debuff();
} while (invalid_date(student->date));
do /*** Lecture Note ****/
{
cls();
printf("\n Note sur 20 : \t");
scanf("%d",&student->note);
debuff();
} while (student->note<0 || student->note>20);
}
void print_etd ( Etd student)
{
printf("\n ID :\t %d",student.ID);
printf("\n Nom :\t %s",student.name);
printf("\n Date :\t %d/%d/%d",student.date.jj,student.date.mm,student.date.aa);
printf("\n Note :\t %d",student.note);
}
liste * creer()
{
liste*NewCell;
NewCell=(liste*)malloc(sizeof(liste));
NewCell->suivant=NULL;
return NewCell;
}
liste*Ajouter(liste*premier)
{
liste*p=premier;
liste*New=creer();
scan_etd(&New->student);
if (!p) return New;
while (p->suivant)
p=p->suivant;
p->suivant=New;
return premier;
}
liste* inserer(liste*premier)
{
liste*p;
p=creer();
scan_etd(&p->student);
p->suivant=premier;
premier=p;
return premier;
}
liste* searchID(liste*premier)
{
liste*p=premier;
liste*q=NULL;
int wanted;
char choix;
printf("\n ID ??\t"); scanf("%d",&wanted);
while ( p && p->student.ID != wanted)
{ q=p;
p=p->suivant;
}
if (!p)
{ printf("\n Aucun Resultat, Essayez autre chose"); return premier; }
print_etd(p->student);
printf("\n Que faire ? \n °M°odifier °S°upprimer ° Autre touche pour retourner ° ");
choix=getch();
if (choix=='M' || choix=='m')
scan_etd(&p->student);
if (choix=='S' || choix=='s');
{ q->suivant=p->suivant;
free(p);
}
return premier;
}
int main()
{
char choix;
int choix2,i;
liste*premier;
int wanted;
printf("\nAppuyer sur une touche :\n");
printf("___________________________\n");
printf("\n °A°jouter\n °S°upprimer\n °R°echercher\n °T°rier\n °ESC° pour quitter ");
//choix=getch();
//for(i=0;i<3;i++)
premier=Ajouter(premier);
//premier=inserer(premier);
if (!premier) return -666;
premier=searchID(premier);
debuff();
return EXIT_SUCCESS;
} |
Partager