Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
 
typedef struct  header_posix{
  char  name[100];
  char  mode[8];
  char  uid[8];
  char  gid[8];
  char  size[12];
  char  mtime[12];
 
} t_hearder;
 
 
int     main(int argc, char **argv)
{
  int fd;
  struct stat header;
  struct header_posix header_p;
 
  fd = open("archive", O_CREAT | O_WRONLY | O_TRUNC, S_IRWXO);
  stat("f1.c", &header);
  sprintf(header_p.name, "%s", "f1.c");
  sprintf(header_p.mode, "%d", header.st_mode);
  sprintf(header_p.uid, "%d", header.st_uid);
  sprintf(header_p.gid, "%d", header.st_gid);
  sprintf(header_p.size, "%d", header.st_size);
  sprintf(header_p.mtime, "%d", header.st_mtime); //jusqu'ici ca marche                                                  
   write(fd, &header_p, sizeof(header_p)); // le probleme se trouve ici 
  return (0);
}
En effet comment inclure l'integralite du contenu de la structure "header_p" dans un fichier.