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
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include"ajouter.c"
#define taille 30
struct eleve
{
char nom[25];
char prenom[25];
};
struct association
{
char nomA;
char description;
char nomT;
char nomP;
char nomS;
int local;
};
void ajouterAssoc(struct association tab[], int position)
{
__fpurge(stdin);
printf("Entrez le nom de l'association :");
fgets(tab[position].nomA, 25, stdin);
__fpurge(stdin);
printf("Entrez la description de l'association :");
fgets(tab[position].description, 100, stdin);
__fpurge(stdin);
printf("Entrez le nom du président :");
fgets(tab[position].nomP, 25, stdin);
__fpurge(stdin);
printf("Entrez le nom du secrétaire :");
fgets(tab[position].nomS, 25, stdin);
__fpurge(stdin);
printf("Entrez le nom du trésorier :");
fgets(tab[position].nomT, 25, stdin);
printf("Entrez le numero du local :");
scanf("%d",&tab[position].local);//A FAIRE : verifier que le local n'est pas encore occupé
}
void enregistrer(struct association tab[], int position)
{
FILE*fichier;
int i;
fichier=fopen("assoc.dat","r");
for(i=0; i<position; i++)
fwrite(&tab[i], sizeof(struct association), 1, fichier);
fclose(fichier);
}
int lire(struct association tab[taille])
{
int i=0;
FILE*fichier=fopen("assoc.dat","r");
while(fread(&tab[i], sizeof(struct association), 1, fichier) && !feof(fichier))
i++;
fclose(fichier);
return i;
}
int main()
{
int indice=0;
struct association tableau[taille];
indice=lire(tableau);
ajouterAssoc(tableau, indice);
} |
Partager