Bonjour,

Je suis entrain de recoder moi même certaine fonction de string.h, afin de verifier mes connaissance et ma compression de leurs effets.

Néanmoins je bloque sur la fonction strstr, qui chercher une chaîne de caractères dans une chaîne de caractères.

Voici mon code:

Code c : 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
 
int main(int argc, char *argv [])
 {
     char *Next_String;
 
     Next_String = String_In_String ("Petit texte de test", "test");
 
     if (Next_String != NULL)
      {
          printf("L'occurrence est : %s.\n", Next_String);
      }
 
 
    return 0;
 }
 
int Size_String (char *String)
 {
     char Character = 0;
     int Number_Of_Character = 0;
 
     do
      {
          Character = String [Number_Of_Character];
          Number_Of_Character ++;
      } while(Character != '\0');
 
    return Number_Of_Character;
 }
int Comp_String (const char *String_1, const char *String_2)
 {
     int Size = 0, Size_1 = 0, Size_2 = 0, Comp = 0, i;
 
     Size_1 = Size_String (String_1);
     Size_2 = Size_String (String_2);
 
     Size = Size_1 - Size_2;
 
     if (Size == 0)
      {
          for(i=0; i<Size; i++)
           {
               if (String_1 [i] == String_2 [i])
                {
                    Comp = 0;
                    //printf("Les chaines sont identiques.\n\n");
                    return Comp;
                }
           }
      }
 
     else
      {
          if (Size > 0)
           {
               Comp = 1;
               printf("Les chaines sont differentes, la premiere etant plus grande que la seconde.\n\n");
               return Comp;
           }
 
          if (Size < 0)
           {
               Comp = -1;
               printf("Les chaines sont differentes, la premiere etant plus petite que la seconde.\n\n");
               return Comp;
           }
      }
 }
 
char *String_In_String (const char *String_1, const char *String_2)
 {
     int Size = 0, Size_1 = 0, Size_2 = 0, Comp = 0, i, k;
     char *Occurrence = 0;
 
     Size_1 = Size_String (String_1);
     Size_2 = Size_String (String_2);
 
     Comp = Comp_String (String_1, String_2);
 
     for(i=0; i<Size_1; i++)
      {
          for(k=0; k<Size_2; k++)
           {
               if ( (String_1 [i] == String_2 [k]))
                {
                    return String_1 - Size_2;
                }
           }
      }
 
    return NULL;
 }

De plus si quelqu'un connais des exo (corrigés de preference) sur les pointeurs ca m'aiderait pas mal je pense =), merci.