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
| #include <stdio.h>
#include <stdlib.h>
typedef struct employe
{
char cin[10];
char nom[10];
float salaire;
}Emp ;
typedef struct machine
{
char adr_mac[10];
char nom_machine[13];
char nom_admin[10];
}Mac ;
typedef struct service
{
int code_s ;
char nom_s[15];
Emp *liste_e ; //tableau dynamique d'employés
Mac *list_m ;//table dynamique ds machines
}Ser ;
Ser *s; // tableau dynamique de services
void *init()
{
s = malloc(sizeof(Ser));
Mac *Amac = malloc(sizeof(Mac));
Emp *Aemp = malloc(sizeof(Emp));
if ( s == NULL || Amac == NULL || Aemp == NULL )
{
exit(EXIT_FAILURE);
}
s->liste_e = Aemp ;
s->list_m = Amac ;
}
void Remplisage_service()
{
char *actuel_c;
FILE *p_file ;
p_file = fopen("DATA.txt","r");
while (actuel_c != EOF)
{
actuel_c = getc(p_file);
if ( actuel_c == 'S')
{
fscanf(p_file ,"%d %s", s->code_s , s->nom_s );
actuel_c = getc(p_file);
}
else if (actuel_c == 'E')
{
fscanf(p_file,"%d %s %d", s->liste_e->cin , s->liste_e->nom , s->liste_e->salaire );
}
else if (actuel_c == 'M')
{
fscanf(p_file,"%s %s %s", s->list_m->adr_mac , s->list_m->nom_machine, s->list_m->nom_admin);
}
}
}
void affichage ()
{
Ser *actuel_service = s ;
Emp *actuel_liste_e = NULL ;
Mac *actuel_liste_m = NULL ;
int C_E , C_M ;
while(actuel_service != NULL)
{
while (actuel_liste_e != NULL)
C_E++ ;
while (actuel_liste_m != NULL)
C_M++ ;
}
printf("le service %s a %d employer et %d machine ", s->nom_s , C_E , C_M);
}
int main()
{
Remplisage_service();
affichage();
return 0 ;
} |
Partager