salut
Voila, je me renseigne sur les pointeurs et ca rentre petit a petit mais la je suis vraiment bloque.
L'allocation dynamique me pose probleme: tabMot.c:55: warning: assignment makes integer from pointer without a cast
En fait j'essai de decouper ma chaine de caractere (ptr) et il faut que je renvoie un char**.
Donc est t-il possible d'allouer a l'indice k et d'y stocker une chaine?
Merci

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
58
59
60
61
62
63
64
65
66
 
#include <stdlib.h>
 
char    *my_strcpy(char *dest, char *src)
{
  int   i;
  int   size;
 
  size = 0;
  while (src[size] != '\0')
    size++;
  for (i = 0; i < (size + 1); i++)
    dest[i] = src[i];
 
  //return (dest);                                               \
                                                                  
}
 
int     nbrCaract(char *ptr, int i)
{
  int   size;
 
  size = 0;
  while (ptr[i]  != ' ' || ptr[i] != '\t')
    size++;
  return (size);
}
char    **tabMot(char *ptr)
{
  int   i;
  int   j;
  int   k;
  char  **tab;
  int taille;
 
  i = 0;
  j = 0;
  k = 0;
  while (ptr[i] != '\0')
    {
      if (ptr[i] != ' ' || ptr[i] != '\t')
        {
          taille = nbrCaract(ptr, i);
          tab[j][k] = malloc(taille * sizeof(char **));
          while (ptr[i] != ' ' || ptr[i] != '\t')
            {
              tab[j][k] = ptr[i];
              k++; i++;
            }
          tab[j][k] = '\0';
        }
      else
        j++;
    }
  return (tab);
}
 
int     main()
{
  char ptr[37];
  char **tab;
 
  my_strcpy(ptr, "test\t affichage chaine  tableau\t c");
  tab = tabMot(ptr);
  //printf("%s", tab[0]);                                         
}
edit: code complet