SHARE
TWEET

my_strpbrk

davk Jan 14th, 2020 (edited) 76 in 23 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int strlength(const char chaine[])
  5. {
  6.     int length = 0;
  7.     char c;
  8.     do
  9.     {
  10.         c = chaine[length];
  11.         length++;
  12.     }
  13.     while(c != '\0');
  14.     length--;
  15.     return length;
  16. }
  17.  
  18. char* my_strpbrk(const char chaine[], const char* letters)
  19. {
  20.     int length = strlength(letters);
  21.     int ch;
  22.     int ch2;
  23.     int strlen = 0;
  24.     char *chr = NULL;
  25.     do
  26.     {
  27.         ch = chaine[strlen];
  28.         for(int i = 0; i < length; i++)
  29.         {
  30.             ch2 = letters[i];
  31.             if(ch == ch2)
  32.             {
  33.                 return &chaine[strlen];
  34.             }
  35.         }
  36.         strlen++;
  37.     }
  38.     while(ch != '\0');
  39.  
  40.     return chr;
  41.  
  42. }
  43.  
  44. int main()
  45. {
  46.     char chaine[100] = "start a new sentence.";
  47.     char *suite = NULL;
  48.  
  49.     suite = my_strpbrk(chaine, "ane");
  50.     printf("here is the sentence starting after the first found letter : %s", suite);
  51.     return 0;
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top