Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct {
- char nom[100];
- int age;
- }Perso;
- void remp(int n, Perso* t)
- {int i ;
- for(i=0;i<n;i++)
- {
- printf("\nPersonne %d : ", i+1);
- printf("\nentrer le nom: ");
- scanf("%s", (t+i)->nom);
- printf("\nentrer lage: ");
- scanf("%d",&(t+i)->age);//"&" na9sa
- printf("\n-----Saved successfully-----");
- }
- }
- int main ()
- {int n ;
- // Declaration Dynamique de tableau de Personnes
- Perso *t=NULL;//* mouch fi blasetha
- printf("entrer le nombre de personne a ajouter svp : \n");
- scanf("%d",&n);
- t=(Perso*)malloc(n*sizeof(Perso));
- remp(n,t); // remplit un tableau de personnes
- FILE* file=NULL;
- file=fopen("Personnes.bin","wb");
- // Copier le Tableau de Personne Dans un fichier binaire
- if (file!=NULL)
- {
- fwrite(t,sizeof(*t),sizeof(t)/sizeof(t[0]),file);
- printf("\n Vector Successfully copied to the File ");
- }
- return 0;//return mathamech
- }
Advertisement
Add Comment
Please, Sign In to add comment