Bonjour,

J'essaye d'écrire en C la fonction strstr en C, mais le problème quand j'exécute le programme il me renvoit meme les caractères qui ne sont pas identique avec le string que je compare avec
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
 
#include <stdio.h>
#include <stdlib.h>
 
 
/* Driver Function */ 
char * StrStr(const char *string1, const char *string2) {  
    if (!*string2)
        return (char *)string1;
    if (!*string1) 
        return NULL;
    if ((*string1 == *string2) && (StrStr(string1+1, string2+1) == string1+1)) 
        return (char *)string1;
    return StrStr(string1+1  , string2);
}
 
/* Main Method */
int main(int argc, char * argv[])
{
 
    printf ("Returned String 1: %s\n", StrStr(argv[1], argv[2]));
 
	return 0;
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
-SVF1521A7EB:~$ ./strs  kkabck abc
Returned String 1: abck
alors que moi je veux qui me renvois juste abc

merci