Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- //Version avec pointeurs ....
- int containts(char * str,char * sub){
- char *ref=sub;//garde adresse originale de sub
- while (*str && *sub){//Pendant que str ou sub no arrive pas à la fin '\0'
- if (*str++==*sub){// str[++]==sub[] ?
- sub++;
- if (!(*sub)){return 1;} //sub[]=='\0' ?
- }else {sub=ref;}//Reset pointeur sub au valeur d'entree ...
- }
- return 0;
- }
- int main()
- {
- char *str = "abcdefgh";
- char *sub = "cde";
- containts(str,sub) ? printf ("Find = %s !\n",sub):printf ("Not find = %s !\n",sub);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement