lonsomehell

mahmoud

May 2nd, 2013
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct {
  6.         char nom[100];
  7.         int age;
  8.     }Perso;
  9.    
  10.  
  11.  
  12.  
  13. void remp(int n, Perso* t)
  14. {int i ;
  15.    
  16.     for(i=0;i<n;i++)
  17.     {
  18.       printf("\nPersonne %d  : ", i+1);
  19.       printf("\nentrer le nom:   ");
  20.       scanf("%s", (t+i)->nom);
  21.       printf("\nentrer lage:    ");
  22.       scanf("%d",&(t+i)->age);//"&" na9sa
  23.       printf("\n-----Saved successfully-----");
  24.        
  25.     }
  26.  
  27. }
  28.    
  29.  
  30. int main ()
  31. {int n ;
  32.  
  33. // Declaration Dynamique de tableau de Personnes
  34.    
  35. Perso *t=NULL;//* mouch fi blasetha
  36.     printf("entrer le nombre de personne a ajouter svp :   \n");
  37.     scanf("%d",&n);
  38.     t=(Perso*)malloc(n*sizeof(Perso));
  39.    
  40.  
  41.  
  42.  
  43. remp(n,t); // remplit un tableau de personnes
  44.  
  45.  
  46. FILE* file=NULL;
  47. file=fopen("Personnes.bin","wb");
  48.  
  49.  
  50. // Copier le Tableau de Personne Dans un fichier binaire
  51. if (file!=NULL)
  52.     {
  53.         fwrite(t,sizeof(*t),sizeof(t)/sizeof(t[0]),file);
  54.         printf("\n Vector Successfully copied to the File ");
  55.     }
  56.  
  57.    
  58.    
  59.    
  60.    
  61.    
  62.    
  63. return 0;//return mathamech
  64. }
Advertisement
Add Comment
Please, Sign In to add comment