[ create a new paste ] login | about

Link: http://codepad.org/Ip32g91R    [ raw code | output | fork ]

C++, pasted on Oct 14:
#include <stdio.h>


// strchr
const char*  _strchr(const char* s, int c) {
   while(*s) {
      if(*s == c)
           return s;
      ++s;
   }
   return NULL;
}



// strstr
const char* _strstr(const char* s1, const char* s2) {
    const char* p = s2;
    while(*s1) {
        if(*s1 == *p) {
            if(! *(++p))
                 return (s1 - (p - s2))+1;
        } else  {
            p = s2;
            if(*p == *s1)
                ++p;
        }
        ++s1;
    }
    return NULL;
}




int main(void){
    puts( _strchr("var BOOL", 'B') );
    puts( _strstr("bsr, code lang(D)", "code") );
    return 0;
}


Output:
1
2
BOOL
code lang(D)


Create a new paste based on this one


Comments: