Zaibon

Untitled

May 5th, 2011
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. short ouvrier_init(char path[],Ouvrier *pOuvrier)
  2. {
  3.     FILE *pf = fopen(path,"rb");
  4.     short retour = 1,i;
  5.     /*Vérificatioin que le fichier ouvrier existe*/
  6.     if(pf==NULL)
  7.     {
  8.         /*si pas de fichier on le crée*/
  9.         pf = fopen(path,"wb");
  10.         if(pf == NULL)
  11.         {
  12.             printf("Impossible de crée le fichier ouvrier, arret du programme\n");
  13.             retour = 0;
  14.         }
  15.         else/*bidonnage du fichier*/
  16.         {
  17.             pOuvrier->NumRegistre = -1;
  18.             strcpy(pOuvrier->nom," ");
  19.             strcpy(pOuvrier->prenom," ");
  20.             strcpy(pOuvrier->rue," ");
  21.             pOuvrier->codePostal = -1;
  22.             strcpy(pOuvrier->ville," ");
  23.             strcpy(pOuvrier->specialite," ");
  24.             pOuvrier->naissance.jour = -1;
  25.             pOuvrier->naissance.mois = -1;
  26.             pOuvrier->naissance.annee = -1;
  27.             pOuvrier->engagement.jour = -1;
  28.             pOuvrier->engagement.mois = -1;
  29.             pOuvrier->engagement.annee = -1;
  30.             /*écriture dans le fichier*/
  31.             if ( fwrite(pOuvrier,sizeof(Ouvrier),100,pf) != 100)
  32.             {
  33.                 printf("Erreur lors du bidonnage du fichier\n");
  34.                 retour = 0;
  35.             }
  36.             else
  37.             {
  38.                 printf("Bidonnage du fichier %s effectue\n",path);
  39.             }
  40.         }
  41.     }
  42.  
  43.     return retour;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment