SHARE
TWEET

Untitled

a guest Mar 25th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <stdio.h>
  3.  
  4. int strend(const char *s, const char *t){
  5.   int i = 0;
  6.   int j = 0;
  7.  
  8.   while(*(s+i) != '\0'){
  9.     i++;
  10.   }
  11.   while(*(t+j) != '\0'){
  12.     j++;
  13.   }
  14.  
  15.   if(j > i){
  16.     return 0;
  17.   }
  18.  
  19.   while(j >= 0){
  20.     if(*(s+i) != *(t+j)){
  21.       return 0;
  22.     }
  23.     i--;
  24.     j--;
  25.   }
  26.  
  27.   return 1;
  28.    
  29. }
  30.  
  31. char *strchr(const char *s, int c){
  32.   char* lastOccurrence = NULL;
  33.   int i = 0;
  34.   while(*(s+i) != '\0'){
  35.  
  36.     if(*(s+i) == c){
  37.       lastOccurrence = s+i;
  38.     }
  39.      
  40.     i++;
  41.   }
  42.  
  43.   return lastOccurrence;
  44. }
  45.  
  46. char *strstr(const char *s, const char *t){
  47.   int sizeT = 0, sizeS = 0;
  48.   for(;*(t+sizeT) != '\0'; sizeT++){}
  49.   for(;*(s+sizeS) != '\0'; sizeS++){}
  50.    
  51.   if(sizeT > sizeS){
  52.     return NULL;
  53.   }
  54.  
  55.   int valid;
  56.   for(int i = 0; i <= sizeS-sizeT; i++){
  57.     valid = 1;
  58.     for(int j = 0; j < sizeT && valid; j++){
  59.       if( *(s+i+j) != *(t+j) ){
  60.     valid = 0;
  61.       }
  62.     }
  63.     if(valid){
  64.       return s+i;
  65.     }
  66.   }
  67.  
  68.   return NULL;
  69. }
  70.  
  71. /*
  72. int main(){
  73.   int i = 0, j = 0;
  74.   char str1[128];
  75.   char str2[128];
  76.  
  77.   while( (str1[i] = getchar()) != '\n' ){
  78.     i++;
  79.   }
  80.   str1[i] = '\0';
  81.   while( (str2[j] = getchar()) != '\n' ){
  82.     j++;
  83.   }
  84.   str2[j] = '\0';
  85.  
  86.   printf("Gelesene Strings\n");
  87.   printf("1. : %s\n", str1);
  88.   printf("2. : %s\n", str2);
  89.   printf("Ergebnis: %s\n", strstr(str1, str2));
  90.    
  91. }
  92. */
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