All pastes #500765 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-05-21 18:39 UTC
rendered paste body
/*
 * franjo stipanovic
 * programiranje - vj 8 1
 * forbidden to use functions from string.h
*/
#include <stdio.h>
#include <ctype.h>
char *strstr_(const char *s1, const char *s2);
int main()
{
   printf("%s\n", strstr_("franjo stipanovic", "StIP"));
   getche();
   return 0;
}
char *strstr_(const char *s1, const char *s2)
{
   char *p1 = s1, *p2 = NULL, *p3 = NULL;
   int eq;
   while (*p1) {
      if (tolower(*p1) == tolower(*s2)) {
         p3 = p1;
         p2 = s2;
         eq = 1;
         while (*p2) {
            if (tolower(*p2) != tolower(*p3)) {
               eq = 0;
               break;
            }
            p2++;
            p3++; 
         }
         if (eq) {
            return p1;
            break;
         }
      }
      p1++; 
   }
   return NULL;
}