Bonjour

Mon ecole m'as donne comme projet de recoder ls (pas toutes ses fonctions hein , mais quand meme ...) donc j'ai decider de me debrouiller avec des listes chaines pour contenir les informations sur les fichiers (actuellement seulement les dirent je n'ai pas encore utiliser stat) .

Seulement je n'arrive pas a afficher les informations que je rentre dans ces liste chaine (J'aimerais verifier si ca fonctionne ...) car je ne trouve pas comment afficher un element d'une structure situer dans une autre structure ...

J'ai tenter cette approche : my_putstr(*(current->data)->d_name);
et celle ci : my_putstr(current->data->d_name);

Donc heellpppp

Sinon voila les bout de code (principaux) correspondant a peu pres au contexte :

PS : Ce code est mega crade je sais, pas besoin de le faire remarquer c'est juste que il a subit pas mal d'experimentation ce matin

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
typedef struct	list_ls
{
  struct list_ls	*next;
  struct dirent		*data;
}		t_list;
 
void	my_ls_put_in_list(struct dirent *dcur, t_list *current)
{
  t_list *snext;
 
  snext = malloc(sizeof(*snext));
  current->data = dcur;
  current->next = snext;
  current = snext;
  my_putchar('.');
}
 
void	my_ls_print_list(t_list *current)
{
  while (current->next != 0)
    {
      my_putstr(*(current->data)->d_name);
      my_putchar('\n');
      current = current->next;
    }
  my_putstr(current->data->d_name);
  my_putchar('\n');
}
 
int	my_ls(char *path)
{
  DIR	*dir_fd;
  int	mep;
  struct dirent *dp;
  t_list *begin;
  t_list *current;
 
  begin = malloc(sizeof(*begin));
  current = begin;
  mep = 0;
  dir_fd = opendir(path);
  while ((dp = readdir(dir_fd)) != NULL)
      my_ls_put_in_list(dp, current);
  my_ls_put_in_list(0, current);
  my_putchar('\n');
  my_ls_print_list(begin);
  /*while (dp != NULL)
    {
      if (dp->d_name[0] != '.')
	my_putstr(dp->d_name);
      dp = readdir(dir_fd);
      if (dp != NULL && dp->d_name[0] != '.')
	my_putchar('\n');
    }
    my_putchar('\n');*/
  return (0);
}