Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int strlength(const char chaine[])
- {
- int length = 0;
- char c;
- do
- {
- c = chaine[length];
- length++;
- }
- while(c != '\0');
- length--;
- return length;
- }
- const char* strstr(const char chaine[], const char* search)
- {
- int strlen = 0;
- char ch;
- int length = strlength(search);
- char* str = NULL;
- do
- {
- int strlen2 = 0;
- int c = 0;
- char ch2;
- ch = chaine[strlen];
- printf("%c\n", ch);
- strlen++;
- do
- {
- ch2 = search[strlen2];
- if(chaine[strlen] == search[strlen2])
- {
- c++;
- strlen++;
- printf("%c\n", ch2);
- if(c == length)
- {
- str = &chaine[strlen-length];
- }
- }
- strlen2++;
- }
- while(ch2 != '\0');
- }
- while (ch != '\0');
- return str;
- }
- int main()
- {
- char chaine[100] = "start a new sentence.";
- char chaine2[100] = "i am starting this new sentence.";
- const char *suite = NULL;
- suite = strstr(chaine2, "sent");
- printf("here is the sentence starting from the found string : %s", suite);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement